CM3D2 Converter.misc_RENDER_PT_bake

   1# 「プロパティ」エリア → 「レンダー」タブ → 「ベイク」パネル
   2import os
   3import bpy
   4import numpy
   5import bmesh
   6import mathutils
   7from . import common
   8from . import compat
   9from .translations.pgettext_functions import *
  10
  11
  12# メニュー等に項目追加
  13def menu_func(self, context):
  14    col = self.layout.column(align=True)
  15    col.label(text="CM3D2用ベイク", icon_value=common.kiss_icon())
  16    row = col.row(align=True)
  17    row.operator('object.add_bake_image', icon=compat.icon('FILE_IMAGE'), text="新規画像")
  18    row.operator('object.quick_ao_bake_image', icon='BRUSH_TEXFILL', text="AO (重)")
  19    row.operator('object.quick_dirty_bake_image', icon='MATSPHERE', text="擬似AO")
  20    row = col.row(align=True)
  21    row.operator('object.quick_hemi_bake_image', icon=compat.icon('LIGHT_HEMI'), text="ヘミライト")
  22    row.operator('object.quick_shadow_bake_image', icon='IMAGE_ALPHA', text="影 (重)")
  23    row.operator('object.quick_side_shadow_bake_image', icon='ARROW_LEFTRIGHT', text="側面陰")
  24    row = col.row(align=True)
  25    row.operator('object.quick_gradation_bake_image', icon='MESH_PLANE', text="グラデーション")
  26    row.operator('object.quick_uv_border_bake_image', icon=compat.icon('CLIPUV_DEHLT'), text="UV縁")
  27    row.operator('object.quick_mesh_border_bake_image', icon='OUTLINER_DATA_MESH', text="メッシュ縁")
  28    row = col.row(align=True)
  29    row.operator('object.quick_density_bake_image', icon='STICKY_UVS_LOC', text="密度")
  30    row.operator('object.quick_bulge_bake_image', icon='BRUSH_INFLATE', text="膨らみ")
  31    row.operator('object.quick_mesh_distance_bake_image', icon=compat.icon('MOD_DATA_TRANSFER'), text="メッシュ間距離")
  32    row = col.row(align=True)
  33    row.operator('object.quick_metal_bake_image', icon=compat.icon('BRUSH_SOFTEN'), text="金属")
  34    row.operator('object.quick_hair_bake_image', icon='PARTICLEMODE', text="髪")
  35    row.operator('object.quick_semen_bake_image', icon='MOD_FLUIDSIM', text="白い液体")
  36
  37
  38@compat.BlRegister()
  39class CNV_OT_add_bake_image(bpy.types.Operator):
  40    bl_idname = 'object.add_bake_image'
  41    bl_label = "ベイク用の画像を作成"
  42    bl_description = "アクティブオブジェクトに素早くベイク用の空の画像を用意します"
  43    bl_options = {'REGISTER', 'UNDO'}
  44
  45    image_name = bpy.props.StringProperty(name="画像名")
  46    items = [
  47        ('128', "128 px", "", 'LAYER_USED', 1),
  48        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
  49        ('512', "512 px", "", 'HAND', 3),
  50        ('1024', "1024 px", "", 'FILE_TICK', 4),
  51        ('2048', "2048 px", "", 'ERROR', 5),
  52        ('4096', "4096 px", "", 'CANCEL', 6),
  53        ]
  54    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
  55    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
  56    image_color = bpy.props.FloatVectorProperty(name="色", default=(1, 1, 1, 1), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=4)
  57
  58    @classmethod
  59    def poll(cls, context):
  60        if len(context.selected_objects) != 1:
  61            return False
  62        ob = context.active_object
  63        if ob:
  64            if ob.type == 'MESH':
  65                me = ob.data
  66                if len(me.uv_layers):
  67                    return True
  68        return False
  69
  70    def invoke(self, context, event):
  71        ob = context.active_object
  72        self.image_name = ob.name + " Bake"
  73        return context.window_manager.invoke_props_dialog(self)
  74
  75    def draw(self, context):
  76        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
  77        self.layout.prop(self, 'image_name', icon='SORTALPHA')
  78        row = self.layout.row(align=True)
  79        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
  80        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
  81        self.layout.prop(self, 'image_color', icon='COLOR')
  82
  83    def execute(self, context):
  84        ob = context.active_object
  85        me = ob.data
  86        ob.hide_render = False
  87
  88        image_width, image_height = int(self.image_width), int(self.image_height)
  89
  90        if self.image_name in context.blend_data.images:
  91            img = context.blend_data.images[self.image_name]
  92        else:
  93            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
  94
  95        area = common.get_request_area(context, 'IMAGE_EDITOR')
  96        common.set_area_space_attr(area, 'image', img)
  97
  98        img.generated_color = self.image_color
  99
 100        for elem in me.uv_textures.active.data:
 101            elem.image = img
 102
 103        return {'FINISHED'}
 104
 105
 106@compat.BlRegister()
 107class CNV_OT_quick_ao_bake_image(bpy.types.Operator):
 108    bl_idname = 'object.quick_ao_bake_image'
 109    bl_label = "AO・ベイク"
 110    bl_description = "アクティブオブジェクトに素早くAOをベイクします"
 111    bl_options = {'REGISTER', 'UNDO'}
 112
 113    image_name = bpy.props.StringProperty(name="画像名")
 114    items = [
 115        ('128', "128 px", "", 'LAYER_USED', 1),
 116        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 117        ('512', "512 px", "", 'HAND', 3),
 118        ('1024', "1024 px", "", 'FILE_TICK', 4),
 119        ('2048', "2048 px", "", 'ERROR', 5),
 120        ('4096', "4096 px", "", 'CANCEL', 6),
 121    ]
 122    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 123    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 124
 125    items = [
 126        ('RAYTRACE', "レイトレース", "", 'BRUSH_TEXFILL', 1),
 127        ('APPROXIMATE', "近似(AAO)", "", 'MATSPHERE', 2),
 128    ]
 129    ao_gather_method = bpy.props.EnumProperty(items=items, name="処理方法", default='RAYTRACE')
 130    ao_samples = bpy.props.IntProperty(name="精度", default=20, min=1, max=50, soft_min=1, soft_max=50)
 131    ao_hide_other = bpy.props.BoolProperty(name="他オブジェクトの影響を受けない", default=True)
 132
 133    @classmethod
 134    def poll(cls, context):
 135        if len(context.selected_objects) != 1:
 136            return False
 137        ob = context.active_object
 138        if ob:
 139            if ob.type == 'MESH':
 140                me = ob.data
 141                if len(me.uv_layers):
 142                    return True
 143        return False
 144
 145    def invoke(self, context, event):
 146        ob = context.active_object
 147        self.image_name = ob.name + " AO Bake"
 148        return context.window_manager.invoke_props_dialog(self)
 149
 150    def draw(self, context):
 151        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 152        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 153        row = self.layout.row(align=True)
 154        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 155        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 156        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
 157        self.layout.prop(self, 'ao_gather_method', icon='NODETREE', expand=True)
 158        self.layout.prop(self, 'ao_samples', icon='ANIM_DATA')
 159        self.layout.prop(self, 'ao_hide_other', icon='VISIBLE_IPO_OFF')
 160
 161    def execute(self, context):
 162        ob = context.active_object
 163        me = ob.data
 164        ob.hide_render = False
 165
 166        image_width, image_height = int(self.image_width), int(self.image_height)
 167
 168        if self.image_name in context.blend_data.images:
 169            img = context.blend_data.images[self.image_name]
 170        else:
 171            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 172
 173        area = common.get_request_area(context, 'IMAGE_EDITOR')
 174        common.set_area_space_attr(area, 'image', img)
 175
 176        for elem in me.uv_textures.active.data:
 177            elem.image = img
 178
 179        context.scene.world.light_settings.gather_method = self.ao_gather_method
 180        context.scene.world.light_settings.samples = self.ao_samples
 181
 182        if self.ao_hide_other: hide_render_restore = common.hide_render_restore()
 183
 184        context.scene.render.bake_type = 'AO'
 185        context.scene.render.use_bake_normalize = True
 186        context.scene.render.use_bake_selected_to_active = False
 187        bpy.ops.object.bake_image()
 188
 189        if self.ao_hide_other: hide_render_restore.restore()
 190
 191        return {'FINISHED'}
 192
 193
 194@compat.BlRegister()
 195class CNV_OT_quick_dirty_bake_image(bpy.types.Operator):
 196    bl_idname = 'object.quick_dirty_bake_image'
 197    bl_label = "擬似AO・ベイク"
 198    bl_description = "アクティブオブジェクトに素早く擬似AOをベイクします"
 199    bl_options = {'REGISTER', 'UNDO'}
 200
 201    image_name = bpy.props.StringProperty(name="画像名")
 202    items = [
 203        ('128', "128 px", "", 'LAYER_USED', 1),
 204        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 205        ('512', "512 px", "", 'HAND', 3),
 206        ('1024', "1024 px", "", 'FILE_TICK', 4),
 207        ('2048', "2048 px", "", 'ERROR', 5),
 208        ('4096', "4096 px", "", 'CANCEL', 6),
 209        ]
 210    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 211    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 212
 213    blur_strength = bpy.props.FloatProperty(name="ブラー強度", default=1, min=0.01, max=1, soft_min=0.01, soft_max=1, step=10, precision=2)
 214    blur_iterations = bpy.props.IntProperty(name="ブラー反復度", default=1, min=0, max=40, soft_min=0, soft_max=40)
 215    clean_angle = bpy.props.FloatProperty(name="ハイライト角度", default=3.14159, min=0, max=3.14159, soft_min=0, soft_max=3.14159, step=3, precision=0, subtype='ANGLE')
 216    dirt_angle = bpy.props.FloatProperty(name="擬似AO角度", default=0, min=0, max=3.14159, soft_min=0, soft_max=3.14159, step=3, precision=0, subtype='ANGLE')
 217    dirt_only = bpy.props.BoolProperty(name="擬似AOのみ", default=True)
 218
 219    @classmethod
 220    def poll(cls, context):
 221        if len(context.selected_objects) != 1:
 222            return False
 223        ob = context.active_object
 224        if ob:
 225            if ob.type == 'MESH':
 226                me = ob.data
 227                if len(me.uv_layers):
 228                    return True
 229        return False
 230
 231    def invoke(self, context, event):
 232        ob = context.active_object
 233        self.image_name = ob.name + " Dirty AO Bake"
 234        return context.window_manager.invoke_props_dialog(self)
 235
 236    def draw(self, context):
 237        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 238        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 239        row = self.layout.row(align=True)
 240        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 241        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 242        self.layout.label(text="擬似AO設定", icon='BRUSH_TEXFILL')
 243        row = self.layout.row(align=True)
 244        row.prop(self, 'blur_strength', icon='NONE', slider=True)
 245        row.prop(self, 'blur_iterations', icon='NONE')
 246        self.layout.prop(self, 'clean_angle', icon='NONE', slider=True)
 247        row = self.layout.row(align=True)
 248        row.prop(self, 'dirt_angle', icon='NONE', slider=True)
 249        row.prop(self, 'dirt_only', icon='FILE_TICK')
 250
 251    def execute(self, context):
 252        ob = context.active_object
 253        me = ob.data
 254        compat.set_select(ob, False)
 255        ob.hide_render = False
 256
 257        image_width, image_height = int(self.image_width), int(self.image_height)
 258
 259        if self.image_name in context.blend_data.images:
 260            img = context.blend_data.images[self.image_name]
 261        else:
 262            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 263
 264        area = common.get_request_area(context, 'IMAGE_EDITOR')
 265        common.set_area_space_attr(area, 'image', img)
 266        for elem in me.uv_textures.active.data:
 267            elem.image = img
 268
 269        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
 270        temp_ob = context.blend_data.objects.new("quick_dirty_bake_image_temp", temp_me)
 271        compat.link(context.scene, temp_ob)
 272        for vc in temp_me.vertex_colors:
 273            temp_me.vertex_colors.remove(vc)
 274        temp_vertex_color = temp_me.vertex_colors.new(name="quick_dirty_bake_image_temp")
 275        compat.set_active(context, temp_ob)
 276        compat.set_select(temp_ob, True)
 277
 278        override = context.copy()
 279        override['object'] = temp_ob
 280        bpy.ops.paint.vertex_color_dirt(override, blur_strength=self.blur_strength, blur_iterations=self.blur_iterations, clean_angle=self.clean_angle, dirt_angle=self.dirt_angle, dirt_only=self.dirt_only)
 281
 282        temp_ob.update_tag(refresh={'OBJECT', 'DATA'})
 283        context.scene.render.bake_type = 'VERTEX_COLORS'
 284        context.scene.render.use_bake_selected_to_active = False
 285        bpy.ops.object.bake_image(context.copy())
 286
 287        common.remove_data([temp_me, temp_ob])
 288        compat.set_active(context, ob)
 289        compat.set_select(ob, True)
 290
 291        return {'FINISHED'}
 292
 293
 294@compat.BlRegister()
 295class CNV_OT_quick_hemi_bake_image(bpy.types.Operator):
 296    bl_idname = 'object.quick_hemi_bake_image'
 297    bl_label = "ヘミライト・ベイク"
 298    bl_description = "アクティブオブジェクトに素早くヘミライトの陰をベイクします"
 299    bl_options = {'REGISTER', 'UNDO'}
 300
 301    image_name = bpy.props.StringProperty(name="画像名")
 302    items = [
 303        ('128', "128 px", "", 'LAYER_USED', 1),
 304        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 305        ('512', "512 px", "", 'HAND', 3),
 306        ('1024', "1024 px", "", 'FILE_TICK', 4),
 307        ('2048', "2048 px", "", 'ERROR', 5),
 308        ('4096', "4096 px", "", 'CANCEL', 6),
 309        ]
 310    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 311    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 312
 313    lamp_energy = bpy.props.FloatProperty(name="光の強さ", default=1, min=0, max=2, soft_min=0, soft_max=2, step=50, precision=2)
 314
 315    use_ao = bpy.props.BoolProperty(name="AOを使用", default=False)
 316    ao_samples = bpy.props.IntProperty(name="AOの精度", default=20, min=1, max=50, soft_min=1, soft_max=50)
 317    ao_hide_other = bpy.props.BoolProperty(name="他オブジェクトの影響を受けない", default=True)
 318
 319    @classmethod
 320    def poll(cls, context):
 321        if len(context.selected_objects) != 1:
 322            return False
 323        ob = context.active_object
 324        if ob:
 325            if ob.type == 'MESH':
 326                me = ob.data
 327                if len(me.uv_layers):
 328                    return True
 329        return False
 330
 331    def invoke(self, context, event):
 332        ob = context.active_object
 333        self.image_name = ob.name + " Hemi Bake"
 334        return context.window_manager.invoke_props_dialog(self)
 335
 336    def draw(self, context):
 337        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 338        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 339        row = self.layout.row(align=True)
 340        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 341        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 342        self.layout.label(text="ヘミライト設定", icon='LAMP_HEMI')
 343        self.layout.prop(self, 'lamp_energy', icon='LAMP_POINT', slider=True)
 344        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
 345        row = self.layout.row(align=True)
 346        row.prop(self, 'use_ao', icon='FILE_TICK')
 347        row.prop(self, 'ao_samples', icon='ANIM_DATA')
 348        self.layout.prop(self, 'ao_hide_other', icon='VISIBLE_IPO_OFF')
 349
 350    def execute(self, context):
 351        ob = context.active_object
 352        me = ob.data
 353        ob.hide_render = False
 354
 355        override = context.copy()
 356        override['object'] = ob
 357
 358        image_width, image_height = int(self.image_width), int(self.image_height)
 359
 360        if self.image_name in context.blend_data.images:
 361            img = context.blend_data.images[self.image_name]
 362        else:
 363            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 364
 365        area = common.get_request_area(context, 'IMAGE_EDITOR')
 366        common.set_area_space_attr(area, 'image', img)
 367        for elem in me.uv_textures.active.data:
 368            elem.image = img
 369
 370        if self.ao_hide_other:
 371            hide_render_restore = common.hide_render_restore()
 372        material_restore = common.material_restore(ob)
 373
 374        bpy.ops.object.material_slot_add(override)
 375        temp_mate = context.blend_data.materials.new("quick_hemi_bake_image_temp")
 376        ob.material_slots[0].material = temp_mate
 377        temp_mate.diffuse_intensity = 1.0
 378        temp_mate.diffuse_color = (1, 1, 1)
 379
 380        temp_lamp = compat.get_lights(context.blend_data).new("quick_hemi_bake_image_temp", 'HEMI')
 381        temp_ob = context.blend_data.objects.new("quick_hemi_bake_image_temp", temp_lamp)
 382        compat.link(context.scene, temp_ob)
 383        temp_lamp.energy = self.lamp_energy
 384
 385        context.scene.world.light_settings.use_ambient_occlusion = self.use_ao
 386        if self.use_ao:
 387            context.scene.world.light_settings.samples = self.ao_samples
 388            context.scene.world.light_settings.ao_blend_type = 'MULTIPLY'
 389
 390        context.scene.render.bake_type = 'FULL'
 391        context.scene.render.use_bake_selected_to_active = False
 392        bpy.ops.object.bake_image()
 393
 394        common.remove_data([temp_lamp, temp_ob, temp_mate])
 395
 396        material_restore.restore()
 397        if self.ao_hide_other:
 398            hide_render_restore.restore()
 399
 400        return {'FINISHED'}
 401
 402
 403@compat.BlRegister()
 404class CNV_OT_quick_shadow_bake_image(bpy.types.Operator):
 405    bl_idname = 'object.quick_shadow_bake_image'
 406    bl_label = "影・ベイク"
 407    bl_description = "アクティブオブジェクトに素早く影をベイクします"
 408    bl_options = {'REGISTER', 'UNDO'}
 409
 410    image_name = bpy.props.StringProperty(name="画像名")
 411    items = [
 412        ('128', "128 px", "", 'LAYER_USED', 1),
 413        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 414        ('512', "512 px", "", 'HAND', 3),
 415        ('1024', "1024 px", "", 'FILE_TICK', 4),
 416        ('2048', "2048 px", "", 'ERROR', 5),
 417        ('4096', "4096 px", "", 'CANCEL', 6),
 418        ]
 419    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 420    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 421
 422    lamp_max_angle = bpy.props.FloatProperty(name="光源の最大角度", default=0.5236, min=0, max=1.5708, soft_min=0, soft_max=1.5708, step=100, precision=0, subtype='ANGLE', unit='ROTATION')
 423    lamp_count = bpy.props.IntProperty(name="光源の数", default=8, min=1, max=20, soft_min=1, soft_max=20)
 424    is_shadow_only = bpy.props.BoolProperty(name="影のみ", default=False)
 425
 426    @classmethod
 427    def poll(cls, context):
 428        if not len(context.selected_objects):
 429            return False
 430        ob = context.active_object
 431        if ob:
 432            if ob.type == 'MESH':
 433                me = ob.data
 434                if len(me.uv_layers):
 435                    return True
 436        return False
 437
 438    def invoke(self, context, event):
 439        self.image_name = context.active_object.name + " Shadow Bake"
 440        return context.window_manager.invoke_props_dialog(self)
 441
 442    def draw(self, context):
 443        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 444        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 445        row = self.layout.row(align=True)
 446        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 447        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 448        self.layout.label(text="光源設定", icon='LAMP_SUN')
 449        self.layout.prop(self, 'lamp_max_angle', icon='LAMP_AREA', slider=True)
 450        self.layout.prop(self, 'lamp_count', icon='LAMP_POINT')
 451        self.layout.prop(self, 'is_shadow_only', icon='IMAGE_ALPHA')
 452
 453    def execute(self, context):
 454        ob = context.active_object
 455        me = ob.data
 456        ob.hide_render = False
 457
 458        override = context.copy()
 459        override['object'] = ob
 460
 461        image_width, image_height = int(self.image_width), int(self.image_height)
 462
 463        if self.image_name in context.blend_data.images:
 464            img = context.blend_data.images[self.image_name]
 465        else:
 466            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 467
 468        area = common.get_request_area(context, 'IMAGE_EDITOR')
 469        common.set_area_space_attr(area, 'image', img)
 470        for elem in me.uv_textures.active.data:
 471            elem.image = img
 472
 473        hide_render_restore = common.hide_render_restore()
 474        material_restore = common.material_restore(ob)
 475
 476        bpy.ops.object.material_slot_add(override)
 477        temp_mate = context.blend_data.materials.new("quick_shadow_bake_image_temp")
 478        ob.material_slots[0].material = temp_mate
 479
 480        lights = compat.get_lights(context.blend_data)
 481        if self.is_shadow_only:
 482            temp_hemi = lights.new("quick_hemi_bake_image_lamp_temp", 'HEMI')
 483            temp_hemi_ob = context.blend_data.objects.new("quick_hemi_bake_image_lamp_temp", temp_hemi)
 484            compat.link(context.scene, temp_hemi_ob)
 485            temp_hemi.energy = 0.00001
 486
 487        new_lamps = []
 488        lamp_count = (self.lamp_count * 2) - 1
 489        angle_interval = self.lamp_max_angle / self.lamp_count
 490        for x_index in range(lamp_count):
 491            x_angle = angle_interval * (x_index - self.lamp_count + 1)
 492
 493            for y_index in range(lamp_count):
 494                y_angle = angle_interval * (y_index - self.lamp_count + 1)
 495
 496                temp_lamp = lights.new("quick_shadow_bake_image_temp", 'SUN')
 497                temp_lamp.shadow_method = 'RAY_SHADOW'
 498                temp_lamp_ob = context.blend_data.objects.new("quick_shadow_bake_image_temp", temp_lamp)
 499                compat.link(context.scene, temp_lamp_ob)
 500                temp_lamp_ob.rotation_mode = 'XYZ'
 501                temp_lamp_ob.rotation_euler = mathutils.Euler((x_angle, y_angle, 0), 'XYZ')
 502
 503                new_lamps.append(temp_lamp)
 504                new_lamps.append(temp_lamp_ob)
 505
 506        context.scene.render.bake_type = 'SHADOW'
 507        context.scene.render.use_bake_selected_to_active = False
 508        bpy.ops.object.bake_image()
 509
 510        common.remove_data([temp_mate] + new_lamps)
 511        if self.is_shadow_only: common.remove_data([temp_hemi_ob, temp_hemi])
 512
 513        material_restore.restore()
 514        hide_render_restore.restore()
 515
 516        return {'FINISHED'}
 517
 518
 519@compat.BlRegister()
 520class CNV_OT_quick_side_shadow_bake_image(bpy.types.Operator):
 521    bl_idname = 'object.quick_side_shadow_bake_image'
 522    bl_label = "側面陰・ベイク"
 523    bl_description = "アクティブオブジェクトに素早く側面陰をベイクします"
 524    bl_options = {'REGISTER', 'UNDO'}
 525
 526    image_name = bpy.props.StringProperty(name="画像名")
 527    items = [
 528        ('128', "128 px", "", 'LAYER_USED', 1),
 529        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 530        ('512', "512 px", "", 'HAND', 3),
 531        ('1024', "1024 px", "", 'FILE_TICK', 4),
 532        ('2048', "2048 px", "", 'ERROR', 5),
 533        ('4096', "4096 px", "", 'CANCEL', 6),
 534        ]
 535    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 536    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 537
 538    is_bipolarization = bpy.props.BoolProperty(name="二極化を有効", default=True)
 539    bipolarization_threshold = bpy.props.FloatProperty(name="二極化のしきい値", default=0.5, min=0, max=1, soft_min=0, soft_max=1, step=5, precision=2)
 540    bipolarization_blur = bpy.props.FloatProperty(name="二極化のぼかし", default=0.05, min=0, max=1, soft_min=0, soft_max=1, step=1, precision=2)
 541
 542    @classmethod
 543    def poll(cls, context):
 544        if len(context.selected_objects) != 1:
 545            return False
 546        ob = context.active_object
 547        if ob:
 548            if ob.type == 'MESH':
 549                me = ob.data
 550                if len(me.uv_layers):
 551                    return True
 552        return False
 553
 554    def invoke(self, context, event):
 555        self.image_name = context.active_object.name + " SideShade Bake"
 556        return context.window_manager.invoke_props_dialog(self)
 557
 558    def draw(self, context):
 559        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 560        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 561        row = self.layout.row(align=True)
 562        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 563        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 564        self.layout.separator()
 565        self.layout.prop(self, 'is_bipolarization', icon='IMAGE_ALPHA')
 566        row = self.layout.row(align=True)
 567        row.prop(self, 'bipolarization_threshold', icon='NONE', text="しきい値")
 568        row.prop(self, 'bipolarization_blur', icon='NONE', text="ぼかし")
 569
 570    def execute(self, context):
 571        ob = context.active_object
 572        me = ob.data
 573        ob.hide_render = False
 574
 575        override = context.copy()
 576        override['object'] = ob
 577
 578        image_width, image_height = int(self.image_width), int(self.image_height)
 579
 580        if self.image_name in context.blend_data.images:
 581            img = context.blend_data.images[self.image_name]
 582        else:
 583            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True, float_buffer=True)
 584
 585        area = common.get_request_area(context, 'IMAGE_EDITOR')
 586        common.set_area_space_attr(area, 'image', img)
 587        for elem in me.uv_textures.active.data:
 588            elem.image = img
 589
 590        material_restore = common.material_restore(ob)
 591
 592        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
 593        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
 594            data_to.materials = ["Side Shadow"]
 595
 596        bpy.ops.object.material_slot_add(override)
 597        temp_mate = data_to.materials[0]
 598        ob.material_slots[0].material = temp_mate
 599
 600        temp_lamp = compat.get_lights(context.blend_data).new("quick_side_shadow_bake_image_lamp_temp", 'HEMI')
 601        temp_lamp_ob = context.blend_data.objects.new("quick_side_shadow_bake_image_lamp_temp", temp_lamp)
 602        compat.link(context.scene, temp_lamp_ob)
 603
 604        pre_scene_camera = context.scene.camera
 605        temp_camera = context.blend_data.cameras.new("quick_side_shadow_bake_image_camera_temp")
 606        temp_camera_ob = context.blend_data.objects.new("quick_side_shadow_bake_image_camera_temp", temp_camera)
 607        compat.link(context.scene, temp_camera_ob)
 608        temp_camera_ob.rotation_euler[0] = 1.5708
 609        context.scene.camera = temp_camera_ob
 610
 611        context.scene.world.light_settings.use_ambient_occlusion = False
 612
 613        context.scene.render.bake_type = 'FULL'
 614        context.scene.render.use_bake_selected_to_active = False
 615        bpy.ops.object.bake_image()
 616
 617        common.remove_data([temp_mate, temp_lamp_ob, temp_lamp, temp_camera_ob, temp_camera])
 618        context.scene.camera = pre_scene_camera
 619
 620        material_restore.restore()
 621
 622        if self.is_bipolarization:
 623            img_w, img_h, img_c = img.size[0], img.size[1], img.channels
 624            pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
 625            min = self.bipolarization_threshold - (self.bipolarization_blur / 2.0)
 626            max = self.bipolarization_threshold + (self.bipolarization_blur / 2.0)
 627            i = numpy.where(pixels[:,:,:3] <= min)
 628            pixels[:,:,:3][i] = 0.0
 629            i = numpy.where(max <= pixels[:,:,:3])
 630            pixels[:,:,:3][i] = 1.0
 631            if 0.0 < max - min:
 632                i = numpy.where((min < pixels[:,:,:3]) & (pixels[:,:,:3] < max))
 633                pixels[:,:,:3][i] -= min
 634                pixels[:,:,:3][i] *= 1.0 / (max - min)
 635            img.pixels = pixels.flatten()
 636
 637        return {'FINISHED'}
 638
 639
 640@compat.BlRegister()
 641class CNV_OT_quick_gradation_bake_image(bpy.types.Operator):
 642    bl_idname = 'object.quick_gradation_bake_image'
 643    bl_label = "グラデーション・ベイク"
 644    bl_description = "アクティブオブジェクトに素早くグラデーションをベイクします"
 645    bl_options = {'REGISTER', 'UNDO'}
 646
 647    image_name = bpy.props.StringProperty(name="画像名")
 648    items = [
 649        ('128', "128 px", "", 'LAYER_USED', 1),
 650        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 651        ('512', "512 px", "", 'HAND', 3),
 652        ('1024', "1024 px", "", 'FILE_TICK', 4),
 653        ('2048', "2048 px", "", 'ERROR', 5),
 654        ('4096', "4096 px", "", 'CANCEL', 6),
 655        ]
 656    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 657    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 658
 659    @classmethod
 660    def poll(cls, context):
 661        if len(context.selected_objects) != 1:
 662            return False
 663        ob = context.active_object
 664        if ob:
 665            if ob.type == 'MESH':
 666                me = ob.data
 667                if len(me.uv_layers):
 668                    return True
 669        return False
 670
 671    def invoke(self, context, event):
 672        self.image_name = context.active_object.name + " Gradation Bake"
 673        return context.window_manager.invoke_props_dialog(self)
 674
 675    def draw(self, context):
 676        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 677        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 678        row = self.layout.row(align=True)
 679        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 680        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 681
 682    def execute(self, context):
 683        ob = context.active_object
 684        me = ob.data
 685        ob.hide_render = False
 686
 687        override = context.copy()
 688        override['object'] = ob
 689
 690        image_width, image_height = int(self.image_width), int(self.image_height)
 691
 692        if self.image_name in context.blend_data.images:
 693            img = context.blend_data.images[self.image_name]
 694        else:
 695            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 696
 697        area = common.get_request_area(context, 'IMAGE_EDITOR')
 698        common.set_area_space_attr(area, 'image', img)
 699        for elem in me.uv_textures.active.data:
 700            elem.image = img
 701
 702        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
 703        zs = [compat.mul(ob.matrix_world, v.co).z for v in temp_me.vertices]
 704        zs.sort()
 705        me_conter = (zs[0] + zs[-1]) / 2
 706        me_height = zs[-1] - zs[0]
 707
 708        material_restore = common.material_restore(ob)
 709
 710        bpy.ops.object.material_slot_add(override)
 711        temp_mate = context.blend_data.materials.new("quick_gradation_bake_image_temp")
 712        ob.material_slots[0].material = temp_mate
 713        temp_slot = temp_mate.texture_slots.create(0)
 714        temp_tex = context.blend_data.textures.new("quick_gradation_bake_image_temp", 'BLEND')
 715        temp_slot.texture = temp_tex
 716        temp_tex.use_color_ramp = True
 717        temp_slot.mapping_y = 'Z'
 718        temp_slot.mapping_z = 'Y'
 719        temp_slot.texture_coords = 'GLOBAL'
 720        temp_tex.color_ramp.elements[0].color = (0, 0, 0, 1)
 721        temp_tex.use_flip_axis = 'VERTICAL'
 722        temp_slot.offset[1] = -me_conter
 723        temp_slot.scale[1] = 1 / (me_height / 2)
 724
 725        context.scene.render.bake_type = 'TEXTURE'
 726        context.scene.render.use_bake_selected_to_active = False
 727        bpy.ops.object.bake_image()
 728
 729        common.remove_data([temp_me, temp_mate, temp_tex])
 730
 731        material_restore.restore()
 732
 733        return {'FINISHED'}
 734
 735
 736@compat.BlRegister()
 737class CNV_OT_quick_metal_bake_image(bpy.types.Operator):
 738    bl_idname = 'object.quick_metal_bake_image'
 739    bl_label = "金属・ベイク"
 740    bl_description = "アクティブオブジェクトに素早く金属風にベイクします"
 741    bl_options = {'REGISTER', 'UNDO'}
 742
 743    image_name = bpy.props.StringProperty(name="画像名")
 744    items = [
 745        ('128', "128 px", "", 'LAYER_USED', 1),
 746        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 747        ('512', "512 px", "", 'HAND', 3),
 748        ('1024', "1024 px", "", 'FILE_TICK', 4),
 749        ('2048', "2048 px", "", 'ERROR', 5),
 750        ('4096', "4096 px", "", 'CANCEL', 6),
 751        ]
 752    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 753    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 754
 755    mate_color = bpy.props.FloatVectorProperty(name="色", default=(0.22, 0.22, 0.22), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR')
 756    environment_strength = bpy.props.FloatProperty(name="映り込み強さ", default=1, min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2)
 757    highlight_strength = bpy.props.FloatProperty(name="ハイライト強さ", default=0.5, min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2)
 758
 759    @classmethod
 760    def poll(cls, context):
 761        if len(context.selected_objects) != 1:
 762            return False
 763        ob = context.active_object
 764        if ob:
 765            if ob.type == 'MESH':
 766                me = ob.data
 767                if len(me.uv_layers):
 768                    return True
 769        return False
 770
 771    def invoke(self, context, event):
 772        self.image_name = context.active_object.name + " Metal Bake"
 773        return context.window_manager.invoke_props_dialog(self)
 774
 775    def draw(self, context):
 776        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 777        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 778        row = self.layout.row(align=True)
 779        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 780        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 781        self.layout.label(text="金属設定", icon=compat.icon('BRUSH_SOFTEN'))
 782        self.layout.prop(self, 'mate_color', icon='COLOR')
 783        row = self.layout.row(align=True)
 784        row.prop(self, 'environment_strength', icon=compat.icon('BRUSH_SOFTEN'), slider=True)
 785        row.prop(self, 'highlight_strength', icon='BRUSH_TEXFILL', slider=True)
 786
 787    def execute(self, context):
 788        ob = context.active_object
 789        me = ob.data
 790        ob.hide_render = False
 791
 792        override = context.copy()
 793        override['object'] = ob
 794
 795        image_width, image_height = int(self.image_width), int(self.image_height)
 796
 797        if self.image_name in context.blend_data.images:
 798            img = context.blend_data.images[self.image_name]
 799        else:
 800            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 801
 802        area = common.get_request_area(context, 'IMAGE_EDITOR')
 803        common.set_area_space_attr(area, 'image', img)
 804        for elem in me.uv_textures.active.data:
 805            elem.image = img
 806
 807        hide_render_restore = common.hide_render_restore()
 808        material_restore = common.material_restore(ob)
 809
 810        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
 811        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
 812            data_to.materials = ["Metal"]
 813
 814        bpy.ops.object.material_slot_add(override)
 815        temp_mate = data_to.materials[0]
 816        ob.material_slots[0].material = temp_mate
 817        temp_mate.diffuse_color = self.mate_color[:]
 818        temp_mate.texture_slots[0].diffuse_color_factor = self.environment_strength
 819        temp_mate.node_tree.nodes["Mix.001"].inputs[0].default_value = 1.0 - self.highlight_strength
 820
 821        temp_lamp = compat.getlights(context.blend_data).new("quick_metal_bake_image_lamp_temp", 'HEMI')
 822        temp_lamp_ob = context.blend_data.objects.new("quick_metal_bake_image_lamp_temp", temp_lamp)
 823        compat.link(context.scene, temp_lamp_ob)
 824        #temp_lamp.energy = self.lamp_energy
 825
 826        pre_scene_camera = context.scene.camera
 827        temp_camera = context.blend_data.cameras.new("quick_metal_bake_image_camera_temp")
 828        temp_camera_ob = context.blend_data.objects.new("quick_metal_bake_image_camera_temp", temp_camera)
 829        compat.link(context.scene, temp_camera_ob)
 830        temp_camera_ob.rotation_euler[0] = 1.5708
 831        context.scene.camera = temp_camera_ob
 832
 833        context.scene.world.light_settings.use_ambient_occlusion = False
 834
 835        context.scene.render.bake_type = 'FULL'
 836        context.scene.render.use_bake_selected_to_active = False
 837        bpy.ops.object.bake_image()
 838
 839        common.remove_data([temp_mate, temp_lamp_ob, temp_lamp, temp_camera_ob, temp_camera])
 840        context.scene.camera = pre_scene_camera
 841
 842        material_restore.restore()
 843        hide_render_restore.restore()
 844
 845        return {'FINISHED'}
 846
 847
 848@compat.BlRegister()
 849class CNV_OT_quick_hair_bake_image(bpy.types.Operator):
 850    bl_idname = 'object.quick_hair_bake_image'
 851    bl_label = "ヘアー・ベイク"
 852    bl_description = "アクティブオブジェクトに素早くCM3D2の髪風のテクスチャをベイクします"
 853    bl_options = {'REGISTER', 'UNDO'}
 854
 855    image_name = bpy.props.StringProperty(name="画像名")
 856    items = [
 857        ('128', "128 px", "", 'LAYER_USED', 1),
 858        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 859        ('512', "512 px", "", 'HAND', 3),
 860        ('1024', "1024 px", "", 'FILE_TICK', 4),
 861        ('2048', "2048 px", "", 'ERROR', 5),
 862        ('4096', "4096 px", "", 'CANCEL', 6),
 863        ]
 864    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 865    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 866
 867    mate_diffuse_color = bpy.props.FloatVectorProperty(name="髪色", default=(1, 1, 1), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=3)
 868    mate_angel_ring_factor = bpy.props.FloatProperty(name="天使の輪の強さ", default=0.5, min=0, max=1, soft_min=0, soft_max=1, step=50, precision=2)
 869
 870    lamp_energy = bpy.props.FloatProperty(name="光の強さ", default=1, min=0, max=2, soft_min=0, soft_max=2, step=50, precision=2)
 871
 872    use_ao = bpy.props.BoolProperty(name="AOを使用", default=False)
 873    ao_samples = bpy.props.IntProperty(name="AOの精度", default=20, min=1, max=50, soft_min=1, soft_max=50)
 874    ao_hide_other = bpy.props.BoolProperty(name="他オブジェクトの影響を受けない", default=True)
 875
 876    @classmethod
 877    def poll(cls, context):
 878        if len(context.selected_objects) != 1:
 879            return False
 880        ob = context.active_object
 881        if ob:
 882            if ob.type == 'MESH':
 883                me = ob.data
 884                if len(me.uv_layers):
 885                    return True
 886        return False
 887
 888    def invoke(self, context, event):
 889        ob = context.active_object
 890        self.image_name = ob.name + " Hair Bake"
 891        return context.window_manager.invoke_props_dialog(self)
 892
 893    def draw(self, context):
 894        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 895        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 896        row = self.layout.row(align=True)
 897        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 898        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 899        self.layout.label(text="ヘアー設定", icon='PARTICLEMODE')
 900        self.layout.prop(self, 'mate_diffuse_color', icon='COLOR')
 901        self.layout.prop(self, 'mate_angel_ring_factor', icon='BRUSH_TEXFILL', slider=True)
 902        self.layout.label(text="ヘミライト設定", icon='LAMP_HEMI')
 903        self.layout.prop(self, 'lamp_energy', icon='LAMP_POINT', slider=True)
 904        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
 905        row = self.layout.row(align=True)
 906        row.prop(self, 'use_ao', icon='FILE_TICK')
 907        row.prop(self, 'ao_samples', icon='ANIM_DATA')
 908        self.layout.prop(self, 'ao_hide_other', icon=compat.icon('VIS_SEL_01'))
 909
 910    def execute(self, context):
 911        import os.path
 912
 913        ob = context.active_object
 914        me = ob.data
 915        ob.hide_render = False
 916
 917        override = context.copy()
 918        override['object'] = ob
 919
 920        image_width, image_height = int(self.image_width), int(self.image_height)
 921
 922        if self.image_name in context.blend_data.images:
 923            img = context.blend_data.images[self.image_name]
 924        else:
 925            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 926
 927        area = common.get_request_area(context, 'IMAGE_EDITOR')
 928        common.set_area_space_attr(area, 'image', img)
 929
 930        for elem in me.uv_textures.active.data:
 931            elem.image = img
 932
 933        if self.ao_hide_other:
 934            hide_render_restore = common.hide_render_restore()
 935        material_restore = common.material_restore(ob)
 936
 937        temp_lamp = compat.get_lights(context.blend_data).new("quick_hemi_bake_image_lamp_temp", 'HEMI')
 938        temp_lamp_ob = context.blend_data.objects.new("quick_hemi_bake_image_lamp_temp", temp_lamp)
 939        compat.link(context.scene, temp_lamp_ob)
 940        temp_lamp.energy = self.lamp_energy
 941
 942        pre_scene_camera = context.scene.camera
 943        temp_camera = context.blend_data.cameras.new("quick_hemi_bake_image_camera_temp")
 944        temp_camera_ob = context.blend_data.objects.new("quick_hemi_bake_image_camera_temp", temp_camera)
 945        compat.link(context.scene, temp_camera_ob)
 946        temp_camera_ob.rotation_euler[0] = 1.5708
 947        context.scene.camera = temp_camera_ob
 948
 949        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
 950        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
 951            data_to.materials = ["CM3D2 Hair"]
 952
 953        bpy.ops.object.material_slot_add(override)
 954        temp_mate = data_to.materials[0]
 955        ob.material_slots[0].material = temp_mate
 956
 957        temp_mate.diffuse_color = self.mate_diffuse_color
 958        temp_mate.node_tree.nodes["mate_angel_ring_factor"].inputs[0].default_value = self.mate_angel_ring_factor
 959
 960        context.scene.world.light_settings.use_ambient_occlusion = self.use_ao
 961        if self.use_ao:
 962            context.scene.world.light_settings.samples = self.ao_samples
 963            context.scene.world.light_settings.ao_blend_type = 'MULTIPLY'
 964
 965        context.scene.render.bake_type = 'FULL'
 966        context.scene.render.use_bake_selected_to_active = False
 967        bpy.ops.object.bake_image()
 968
 969        temp_tex = temp_mate.texture_slots[0].texture
 970
 971        common.remove_data([temp_mate, temp_tex, temp_camera_ob, temp_camera, temp_lamp_ob, temp_lamp])
 972        context.scene.camera = pre_scene_camera
 973
 974        material_restore.restore()
 975        if self.ao_hide_other:
 976            hide_render_restore.restore()
 977
 978        return {'FINISHED'}
 979
 980
 981@compat.BlRegister()
 982class CNV_OT_quick_uv_border_bake_image(bpy.types.Operator):
 983    bl_idname = 'object.quick_uv_border_bake_image'
 984    bl_label = "UV縁・ベイク"
 985    bl_description = "アクティブオブジェクトに素早くUVの縁を黒くベイクします"
 986    bl_options = {'REGISTER', 'UNDO'}
 987
 988    image_name = bpy.props.StringProperty(name="画像名")
 989    items = [
 990        ('128', "128 px", "", 'LAYER_USED', 1),
 991        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 992        ('512', "512 px", "", 'HAND', 3),
 993        ('1024', "1024 px", "", 'FILE_TICK', 4),
 994        ('2048', "2048 px", "", 'ERROR', 5),
 995        ('4096', "4096 px", "", 'CANCEL', 6),
 996        ]
 997    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 998    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 999
1000    items = [
1001        ('FLAT', "フラット", "", 'IPO_CONSTANT', 1),
1002        ('TENT', "テント", "", 'IPO_LINEAR', 2),
1003        ('QUAD', "二次式", "", 'IPO_QUAD', 3),
1004        ('CUBIC', "三次式", "", 'IPO_CUBIC', 4),
1005        ('GAUSS', "ガウシアン", "", 'HAND', 5),
1006        ('FAST_GAUSS', "高速ガウシアン", "", 'ALIASED', 6),
1007        ('CATROM', "Catrom", "", 'FILE_TICK', 7),
1008        ('MITCH', "Mitch", "", 'FILE_TICK', 8),
1009        ]
1010    blur_type = bpy.props.EnumProperty(items=items, name="ぼかしタイプ", default='GAUSS')
1011    blur_strength = bpy.props.IntProperty(name="ぼかし強度", default=100, min=0, max=1000, soft_min=0, soft_max=1000)
1012    normalize = bpy.props.BoolProperty(name="正規化", default=True)
1013    keep_alpha = bpy.props.BoolProperty(name="余白を透過", default=True)
1014
1015    @classmethod
1016    def poll(cls, context):
1017        if len(context.selected_objects) != 1:
1018            return False
1019        ob = context.active_object
1020        if ob:
1021            if ob.type == 'MESH':
1022                me = ob.data
1023                if len(me.uv_layers):
1024                    return True
1025        return False
1026
1027    def invoke(self, context, event):
1028        ob = context.active_object
1029        self.image_name = ob.name + " UV Border Bake"
1030        return context.window_manager.invoke_props_dialog(self)
1031
1032    def draw(self, context):
1033        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1034        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1035        row = self.layout.row(align=True)
1036        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1037        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1038        self.layout.label(text="縁設定", icon=compat.icon('CLIPUV_DEHLT'))
1039        self.layout.prop(self, 'blur_type', icon='BRUSH_BLUR')
1040        self.layout.prop(self, 'blur_strength', icon='ARROW_LEFTRIGHT')
1041        row = self.layout.row(align=True)
1042        row.prop(self, 'normalize', icon='IMAGE_ALPHA')
1043        row.prop(self, 'keep_alpha', icon='IMAGE_RGB_ALPHA')
1044
1045    def execute(self, context):
1046        ob = context.active_object
1047        me = ob.data
1048        ob.hide_render = False
1049
1050        override = context.copy()
1051        override['object'] = ob
1052
1053        image_width, image_height = int(self.image_width), int(self.image_height)
1054
1055        if self.image_name in context.blend_data.images:
1056            img = context.blend_data.images[self.image_name]
1057        else:
1058            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1059
1060        area = common.get_request_area(context, 'IMAGE_EDITOR')
1061
1062        img.generated_color = (0, 0, 0, 1)
1063
1064        for elem in me.uv_textures.active.data:
1065            elem.image = img
1066
1067        material_restore = common.material_restore(ob)
1068
1069        bpy.ops.object.material_slot_add(override)
1070        temp_mate = context.blend_data.materials.new("quick_gradation_bake_image_temp")
1071        ob.material_slots[0].material = temp_mate
1072        temp_mate.diffuse_color = (1, 1, 1)
1073
1074        pre_use_bake_clear = context.scene.render.use_bake_clear
1075        pre_bake_margin = context.scene.render.bake_margin
1076        context.scene.render.use_bake_clear = False
1077        context.scene.render.bake_type = 'TEXTURE'
1078        context.scene.render.use_bake_selected_to_active = False
1079
1080        bpy.ops.object.bake_image()
1081        img_w, img_h, img_c = img.size[0], img.size[1], img.channels
1082        pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
1083        img_alphas = pixels[:,:,0]
1084
1085        img.reload()
1086        context.scene.render.bake_margin = 0
1087        bpy.ops.object.bake_image()
1088
1089        context.scene.render.use_bake_clear = pre_use_bake_clear
1090        context.scene.render.bake_margin = pre_bake_margin
1091
1092        # 無駄に壮大なぼかし処理
1093        pre_resolution_x = context.scene.render.resolution_x
1094        pre_resolution_y = context.scene.render.resolution_y
1095        pre_resolution_percentage = context.scene.render.resolution_percentage
1096        context.scene.render.resolution_x = img.size[0]
1097        context.scene.render.resolution_y = img.size[1]
1098        context.scene.render.resolution_percentage = 100
1099
1100        context.scene.use_nodes = True
1101        node_tree = context.scene.node_tree
1102        for node in node_tree.nodes:
1103            node_tree.nodes.remove(node)
1104
1105        img_node = node_tree.nodes.new('CompositorNodeImage')
1106        img_node.location = (0, 0)
1107        img_node.image = img
1108
1109        blur_node = node_tree.nodes.new('CompositorNodeBlur')
1110        blur_node.location = (250, 0)
1111        blur_node.size_x, blur_node.size_y = 1, 1
1112        blur_node.filter_type = self.blur_type
1113        blur_node.inputs[1].default_value = self.blur_strength
1114
1115        out_node = node_tree.nodes.new('CompositorNodeComposite')
1116        out_node.location = (500, 0)
1117
1118        node_tree.links.new(blur_node.inputs[0], img_node.outputs[0])
1119        node_tree.links.new(out_node.inputs[0], blur_node.outputs[0])
1120
1121        bpy.ops.render.render()
1122
1123        render_img = context.blend_data.images["Render Result"]
1124
1125        temp_png_path = os.path.join(bpy.app.tempdir, "temp.png")
1126        img_override = context.copy()
1127        img_override['object'] = render_img
1128        img_override['edit_image'] = render_img
1129        img_override['area'] = area
1130        common.set_area_space_attr(area, 'image', render_img)
1131        bpy.ops.image.save_as(img_override, save_as_render=True, copy=True, filepath=temp_png_path, relative_path=False, show_multiview=False, use_multiview=False)
1132        img.source = 'FILE'
1133        img.filepath = temp_png_path
1134        img.reload()
1135        pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
1136        if self.keep_alpha:
1137            pixels[:,:,3] = img_alphas
1138        if self.normalize:
1139            pixels[:,:,:3] -= 0.5
1140            pixels[:,:,:3] *= 2.0
1141        img.pixels = pixels.flatten()
1142        img.pack(as_png=True)
1143        os.remove(temp_png_path)
1144
1145        for node in node_tree.nodes:
1146            node_tree.nodes.remove(node)
1147        context.scene.use_nodes = False
1148        context.scene.render.resolution_x = pre_resolution_x
1149        context.scene.render.resolution_y = pre_resolution_y
1150        context.scene.render.resolution_percentage = pre_resolution_percentage
1151        # 無駄に壮大なぼかし処理 完
1152
1153        common.set_area_space_attr(area, 'image', img)
1154        common.remove_data([temp_mate])
1155        material_restore.restore()
1156
1157        return {'FINISHED'}
1158
1159
1160@compat.BlRegister()
1161class CNV_OT_quick_mesh_border_bake_image(bpy.types.Operator):
1162    bl_idname = 'object.quick_mesh_border_bake_image'
1163    bl_label = "メッシュ縁・ベイク"
1164    bl_description = "アクティブオブジェクトに素早くメッシュの縁を黒くベイクします"
1165    bl_options = {'REGISTER', 'UNDO'}
1166
1167    image_name = bpy.props.StringProperty(name="画像名")
1168    items = [
1169        ('128', "128 px", "", 'LAYER_USED', 1),
1170        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1171        ('512', "512 px", "", 'HAND', 3),
1172        ('1024', "1024 px", "", 'FILE_TICK', 4),
1173        ('2048', "2048 px", "", 'ERROR', 5),
1174        ('4096', "4096 px", "", 'CANCEL', 6),
1175        ]
1176    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1177    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1178
1179    range = bpy.props.IntProperty(name="範囲", default=5, min=1, max=50, soft_min=1, soft_max=50)
1180
1181    @classmethod
1182    def poll(cls, context):
1183        if len(context.selected_objects) != 1:
1184            return False
1185        ob = context.active_object
1186        if ob:
1187            if ob.type == 'MESH':
1188                me = ob.data
1189                if len(me.uv_layers):
1190                    return True
1191        return False
1192
1193    def invoke(self, context, event):
1194        ob = context.active_object
1195        self.image_name = ob.name + " Mesh Border Bake"
1196        return context.window_manager.invoke_props_dialog(self)
1197
1198    def draw(self, context):
1199        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1200        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1201        row = self.layout.row(align=True)
1202        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1203        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1204
1205        self.layout.prop(self, 'range', icon='PROP_ON')
1206
1207    def execute(self, context):
1208        ob = context.active_object
1209        me = ob.data
1210        compat.set_select(ob, False)
1211        ob.hide_render = False
1212
1213        image_width, image_height = int(self.image_width), int(self.image_height)
1214
1215        if self.image_name in context.blend_data.images:
1216            img = context.blend_data.images[self.image_name]
1217        else:
1218            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1219
1220        area = common.get_request_area(context, 'IMAGE_EDITOR')
1221        common.set_area_space_attr(area, 'image', img)
1222        for elem in me.uv_textures.active.data:
1223            elem.image = img
1224
1225        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1226        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1227        compat.link(context.scene, temp_ob)
1228        for vc in temp_me.vertex_colors:
1229            temp_me.vertex_colors.remove(vc)
1230        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1231        compat.set_active(context, temp_ob)
1232        compat.set_select(temp_ob, True)
1233
1234        def paint_selected_vertices(me, color, except_indices=[]):
1235            paint_vertices = []
1236            for vert in me.vertices:
1237                if vert.select and vert.index not in except_indices:
1238                    paint_vertices.append(vert.index)
1239            for loop in me.loops:
1240                if loop.vertex_index in paint_vertices:
1241                    me.vertex_colors.active.data[loop.index].color = color
1242            return paint_vertices
1243
1244        context.tool_settings.mesh_select_mode = (True, False, False)
1245        already_vert_indices = []
1246        for index in range(self.range):
1247            bpy.ops.object.mode_set(mode='EDIT')
1248            if index == 0:
1249                bpy.ops.mesh.reveal()
1250                bpy.ops.mesh.select_all(action='DESELECT')
1251                bpy.ops.mesh.select_non_manifold()
1252            else:
1253                bpy.ops.mesh.select_more()
1254            bpy.ops.object.mode_set(mode='OBJECT')
1255
1256            value = (1.0 / self.range) * index
1257            already_vert_indices += paint_selected_vertices(temp_me, [value, value, value], already_vert_indices)
1258
1259        bpy.ops.object.mode_set(mode='EDIT')
1260        bpy.ops.mesh.select_all(action='DESELECT')
1261        bpy.ops.object.mode_set(mode='OBJECT')
1262
1263        context.scene.render.bake_type = 'VERTEX_COLORS'
1264        context.scene.render.use_bake_selected_to_active = False
1265        bpy.ops.object.bake_image()
1266
1267        common.remove_data([temp_me, temp_ob])
1268        compat.set_active(context, ob)
1269        compat.set_select(ob, True)
1270
1271        return {'FINISHED'}
1272
1273
1274@compat.BlRegister()
1275class CNV_OT_quick_density_bake_image(bpy.types.Operator):
1276    bl_idname = 'object.quick_density_bake_image'
1277    bl_label = "密度・ベイク"
1278    bl_description = "アクティブオブジェクトに素早く密度をベイクします"
1279    bl_options = {'REGISTER', 'UNDO'}
1280
1281    image_name = bpy.props.StringProperty(name="画像名")
1282    items = [
1283        ('128', "128 px", "", 'LAYER_USED', 1),
1284        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1285        ('512', "512 px", "", 'HAND', 3),
1286        ('1024', "1024 px", "", 'FILE_TICK', 4),
1287        ('2048', "2048 px", "", 'ERROR', 5),
1288        ('4096', "4096 px", "", 'CANCEL', 6),
1289        ]
1290    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1291    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1292
1293    items = [
1294        ('ALL', "全て", "", 'MOD_SUBSURF', 1),
1295        ('PARTS', "パーツごと", "", 'GROUP_VCOL', 2),
1296        ]
1297    mode = bpy.props.EnumProperty(items=items, name="比較対象", default='PARTS')
1298
1299    @classmethod
1300    def poll(cls, context):
1301        if len(context.selected_objects) != 1:
1302            return False
1303        ob = context.active_object
1304        if ob:
1305            if ob.type == 'MESH':
1306                me = ob.data
1307                if len(me.uv_layers):
1308                    return True
1309        return False
1310
1311    def invoke(self, context, event):
1312        ob = context.active_object
1313        self.image_name = ob.name + " Density Bake"
1314        return context.window_manager.invoke_props_dialog(self)
1315
1316    def draw(self, context):
1317        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1318        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1319        row = self.layout.row(align=True)
1320        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1321        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1322        self.layout.label(text="比較対象", icon='ZOOM_PREVIOUS')
1323        self.layout.prop(self, 'mode', icon='ZOOM_PREVIOUS', expand=True)
1324
1325    def execute(self, context):
1326        ob = context.active_object
1327        me = ob.data
1328        compat.set_select(ob, False)
1329        ob.hide_render = False
1330
1331        image_width, image_height = int(self.image_width), int(self.image_height)
1332
1333        if self.image_name in context.blend_data.images:
1334            img = context.blend_data.images[self.image_name]
1335        else:
1336            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1337
1338        area = common.get_request_area(context, 'IMAGE_EDITOR')
1339        common.set_area_space_attr(area, 'image', img)
1340        for elem in me.uv_textures.active.data:
1341            elem.image = img
1342
1343        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1344        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1345        compat.link(context.scene, temp_ob)
1346        for vc in temp_me.vertex_colors:
1347            temp_me.vertex_colors.remove(vc)
1348        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1349        compat.set_active(context, temp_ob)
1350        compat.set_select(temp_ob, True)
1351
1352        bm = bmesh.new()
1353        bm.from_mesh(temp_me)
1354        bm.verts.ensure_lookup_table()
1355
1356        vert_islands = []
1357        if self.mode == 'ALL':
1358            vert_islands.append([v.index for v in bm.verts])
1359        elif self.mode == 'PARTS':
1360            alread_vert_indices = []
1361            for i in range(9**9):
1362
1363                vert_islands.append([])
1364
1365                for vert in bm.verts:
1366                    if vert.index not in alread_vert_indices:
1367                        new_verts = [vert]
1368                        alread_vert_indices.append(vert.index)
1369                        vert_islands[-1].append(vert.index)
1370                        break
1371
1372                for j in range(9**9):
1373
1374                    vs = []
1375                    for vert in new_verts:
1376                        for edge in vert.link_edges:
1377                            for v in edge.verts:
1378                                if vert.index != v.index and v.index not in alread_vert_indices:
1379                                    vs.append(v)
1380                                    alread_vert_indices.append(v.index)
1381                                    vert_islands[-1].append(v.index)
1382                                    break
1383
1384                    if not len(vs):
1385                        break
1386
1387                    new_verts = vs[:]
1388
1389                if len(bm.verts) <= len(alread_vert_indices):
1390                    break
1391
1392        for island in vert_islands:
1393            edge_lens = []
1394            for index in island:
1395                lens = [e.calc_length() for e in bm.verts[index].link_edges]
1396                edge_lens.append( sum(lens) / len(lens) )
1397            edge_min, edge_max = min(edge_lens), max(edge_lens)
1398            try:
1399                multi = 1.0 / (edge_max - edge_min)
1400            except:
1401                multi = 1.0
1402
1403            for index in island:
1404                vert = bm.verts[index]
1405
1406                lens = [e.calc_length() for e in vert.link_edges]
1407                l = sum(lens) / len(lens)
1408                value = (l - edge_min) * multi
1409                for loop in vert.link_loops:
1410                    temp_vertex_color.data[loop.index].color = (value, value, value)
1411
1412        context.scene.render.bake_type = 'VERTEX_COLORS'
1413        context.scene.render.use_bake_selected_to_active = False
1414        bpy.ops.object.bake_image()
1415
1416        common.remove_data([temp_me, temp_ob])
1417        compat.set_active(context, ob)
1418        compat.set_select(ob, True)
1419
1420        return {'FINISHED'}
1421
1422
1423@compat.BlRegister()
1424class CNV_OT_quick_mesh_distance_bake_image(bpy.types.Operator):
1425    bl_idname = 'object.quick_mesh_distance_bake_image'
1426    bl_label = "メッシュ間距離・ベイク"
1427    bl_description = "アクティブオブジェクトに他オブジェクトとの距離をベイクします"
1428    bl_options = {'REGISTER', 'UNDO'}
1429
1430    image_name = bpy.props.StringProperty(name="画像名")
1431    items = [
1432        ('128', "128 px", "", 'LAYER_USED', 1),
1433        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1434        ('512', "512 px", "", 'HAND', 3),
1435        ('1024', "1024 px", "", 'FILE_TICK', 4),
1436        ('2048', "2048 px", "", 'ERROR', 5),
1437        ('4096', "4096 px", "", 'CANCEL', 6),
1438        ]
1439    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1440    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1441
1442    @classmethod
1443    def poll(cls, context):
1444        obs = context.selected_objects
1445        if len(obs) != 2: return False
1446        for ob in obs:
1447            if ob.type != 'MESH':
1448                return False
1449        me = context.active_object.data
1450        if len(me.uv_layers):
1451            return True
1452        return False
1453
1454    def invoke(self, context, event):
1455        ob = context.active_object
1456        self.image_name = ob.name + " Mesh Distance Bake"
1457        return context.window_manager.invoke_props_dialog(self)
1458
1459    def draw(self, context):
1460        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1461        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1462        row = self.layout.row(align=True)
1463        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1464        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1465
1466    def execute(self, context):
1467        target_ob = context.active_object
1468        target_ob.hide_render = False
1469        for ob in context.selected_objects:
1470            if ob.name != target_ob.name:
1471                source_ob = ob
1472            compat.set_select(ob, False)
1473        target_me = target_ob.data
1474        source_me = source_ob.data
1475
1476        image_width, image_height = int(self.image_width), int(self.image_height)
1477
1478        if self.image_name in context.blend_data.images:
1479            img = context.blend_data.images[self.image_name]
1480        else:
1481            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1482
1483        area = common.get_request_area(context, 'IMAGE_EDITOR')
1484        common.set_area_space_attr(area, 'image', img)
1485        for elem in target_me.uv_textures.active.data:
1486            elem.image = img
1487
1488        temp_me = target_ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1489        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1490        compat.link(context.scene, temp_ob)
1491        for vc in temp_me.vertex_colors:
1492            temp_me.vertex_colors.remove(vc)
1493        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1494        compat.set_active(context, temp_ob)
1495        compat.set_select(temp_ob, True)
1496
1497        bvh = mathutils.bvhtree.BVHTree.FromObject(source_ob, context.scene)
1498
1499        vert_dists = []
1500        for vert in temp_me.vertices:
1501            co = compat.mul(target_ob.matrix_world, vert.co)
1502            location, normal, index, dist = bvh.find(co)
1503            vert_dists.append(dist)
1504
1505        dist_min, dist_max = min(vert_dists), max(vert_dists)
1506        try:
1507            multi = 1.0 / (dist_max - dist_min)
1508        except:
1509            multi = 1.0
1510
1511        for loop in temp_me.loops:
1512            value = ( vert_dists[loop.vertex_index] - dist_min ) * multi
1513            temp_vertex_color.data[loop.index].color = (value, value, value)
1514
1515        context.scene.render.bake_type = 'VERTEX_COLORS'
1516        context.scene.render.use_bake_selected_to_active = False
1517        bpy.ops.object.bake_image()
1518
1519        common.remove_data([temp_me, temp_ob])
1520        compat.set_active(context, target_ob)
1521        compat.set_select(target_ob, True)
1522        compat.set_select(source_ob, True)
1523
1524        return {'FINISHED'}
1525
1526
1527@compat.BlRegister()
1528class CNV_OT_quick_bulge_bake_image(bpy.types.Operator):
1529    bl_idname = 'object.quick_bulge_bake_image'
1530    bl_label = "膨らみ・ベイク"
1531    bl_description = "アクティブオブジェクトに膨らんでいる部分を白くベイクします"
1532    bl_options = {'REGISTER', 'UNDO'}
1533
1534    image_name = bpy.props.StringProperty(name="画像名")
1535    items = [
1536        ('128', "128 px", "", 'LAYER_USED', 1),
1537        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1538        ('512', "512 px", "", 'HAND', 3),
1539        ('1024', "1024 px", "", 'FILE_TICK', 4),
1540        ('2048', "2048 px", "", 'ERROR', 5),
1541        ('4096', "4096 px", "", 'CANCEL', 6),
1542        ]
1543    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1544    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1545
1546    @classmethod
1547    def poll(cls, context):
1548        if len(context.selected_objects) != 1:
1549            return False
1550        ob = context.active_object
1551        if ob:
1552            if ob.type == 'MESH':
1553                me = ob.data
1554                if len(me.uv_layers):
1555                    return True
1556        return False
1557
1558    def invoke(self, context, event):
1559        ob = context.active_object
1560        self.image_name = ob.name + " Bulge Bake"
1561        return context.window_manager.invoke_props_dialog(self)
1562
1563    def draw(self, context):
1564        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1565        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1566        row = self.layout.row(align=True)
1567        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1568        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1569
1570    def execute(self, context):
1571        ob = context.active_object
1572        me = ob.data
1573        compat.set_select(ob, False)
1574        ob.hide_render = False
1575
1576        image_width, image_height = int(self.image_width), int(self.image_height)
1577
1578        if self.image_name in context.blend_data.images:
1579            img = context.blend_data.images[self.image_name]
1580        else:
1581            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1582
1583        area = common.get_request_area(context, 'IMAGE_EDITOR')
1584        common.set_area_space_attr(area, 'image', img)
1585        for elem in me.uv_textures.active.data:
1586            elem.image = img
1587
1588        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1589        temp_ob = context.blend_data.objects.new("quick_bulge_bake_image", temp_me)
1590        compat.link(context.scene, temp_ob)
1591        for vc in temp_me.vertex_colors:
1592            temp_me.vertex_colors.remove(vc)
1593        temp_vertex_color = temp_me.vertex_colors.new(name="quick_bulge_bake_image")
1594        compat.set_active(context, temp_ob)
1595        compat.set_select(temp_ob, True)
1596
1597        bm = bmesh.new()
1598        bm.from_mesh(temp_me)
1599
1600        angles = []
1601        for vert in bm.verts:
1602            normal = vert.normal
1603            edge_angle_total = 0.0
1604            for edge in vert.link_edges:
1605                diff_co = edge.other_vert(vert).co - vert.co
1606                if 0 < diff_co.length:
1607                    edge_angle_total += normal.angle(diff_co)
1608            if len(vert.link_edges):
1609                edge_angle = edge_angle_total / len(vert.link_edges)
1610            else:
1611                edge_angle = 0.0
1612            angles.append(edge_angle)
1613
1614        angle_min, angle_max = 1.5708, max(angles)
1615        multi = 1.0 / (angle_max - angle_min)
1616
1617        for vert in bm.verts:
1618            value = (angles[vert.index] - angle_min) * multi
1619            for loop in vert.link_loops:
1620                temp_vertex_color.data[loop.index].color = (value, value, value)
1621
1622        context.scene.render.bake_type = 'VERTEX_COLORS'
1623        context.scene.render.use_bake_selected_to_active = False
1624        bpy.ops.object.bake_image()
1625
1626        common.remove_data([temp_me, temp_ob])
1627        compat.set_active(context, ob)
1628        compat.set_select(ob, True)
1629
1630        return {'FINISHED'}
1631
1632
1633@compat.BlRegister()
1634class CNV_OT_quick_semen_bake_image(bpy.types.Operator):
1635    bl_idname = 'object.quick_semen_bake_image'
1636    bl_label = "白い液体・ベイク"
1637    bl_description = "アクティブオブジェクトに白い液体をベイクします"
1638    bl_options = {'REGISTER', 'UNDO'}
1639
1640    image_name = bpy.props.StringProperty(name="画像名")
1641    items = [
1642        ('128', "128 px", "", 'LAYER_USED', 1),
1643        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1644        ('512', "512 px", "", 'HAND', 3),
1645        ('1024', "1024 px", "", 'FILE_TICK', 4),
1646        ('2048', "2048 px", "", 'ERROR', 5),
1647        ('4096', "4096 px", "", 'CANCEL', 6),
1648        ]
1649    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1650    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1651
1652    texture_scale = bpy.props.FloatProperty(name="テクスチャサイズ", default=1, min=0, max=100, soft_min=0, soft_max=100, step=50, precision=1)
1653
1654    @classmethod
1655    def poll(cls, context):
1656        if len(context.selected_objects) != 1:
1657            return False
1658        ob = context.active_object
1659        if ob:
1660            if ob.type == 'MESH':
1661                me = ob.data
1662                if len(me.uv_layers):
1663                    return True
1664        return False
1665
1666    def invoke(self, context, event):
1667        ob = context.active_object
1668        self.image_name = ob.name + " Semen Bake"
1669        return context.window_manager.invoke_props_dialog(self)
1670
1671    def draw(self, context):
1672        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1673        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1674        row = self.layout.row(align=True)
1675        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1676        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1677
1678        self.layout.prop(self, 'texture_scale', icon='TEXTURE')
1679
1680    def execute(self, context):
1681        ob = context.active_object
1682        me = ob.data
1683        ob.hide_render = False
1684
1685        override = context.copy()
1686        override['object'] = ob
1687
1688        image_width, image_height = int(self.image_width), int(self.image_height)
1689
1690        if self.image_name in context.blend_data.images:
1691            img = context.blend_data.images[self.image_name]
1692        else:
1693            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1694
1695        area = common.get_request_area(context, 'IMAGE_EDITOR')
1696        common.set_area_space_attr(area, 'image', img)
1697        for elem in me.uv_textures.active.data:
1698            elem.image = img
1699
1700        material_restore = common.material_restore(ob)
1701
1702        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
1703        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
1704            data_to.materials = ["精液"]
1705
1706        bpy.ops.object.material_slot_add(override)
1707        temp_mate = data_to.materials[0]
1708        ob.material_slots[0].material = temp_mate
1709        temp_mate.texture_slots[0].scale = (self.texture_scale, self.texture_scale, self.texture_scale)
1710
1711        context.scene.render.bake_type = 'TEXTURE'
1712        context.scene.render.use_bake_selected_to_active = False
1713        bpy.ops.object.bake_image()
1714
1715        common.remove_data([temp_mate, temp_mate.texture_slots[0].texture, temp_mate.texture_slots[0].texture.image])
1716
1717        material_restore.restore()
1718
1719        return {'FINISHED'}
@compat.BlRegister()
class CNV_OT_add_bake_image(bpy_types.Operator):
 39@compat.BlRegister()
 40class CNV_OT_add_bake_image(bpy.types.Operator):
 41    bl_idname = 'object.add_bake_image'
 42    bl_label = "ベイク用の画像を作成"
 43    bl_description = "アクティブオブジェクトに素早くベイク用の空の画像を用意します"
 44    bl_options = {'REGISTER', 'UNDO'}
 45
 46    image_name = bpy.props.StringProperty(name="画像名")
 47    items = [
 48        ('128', "128 px", "", 'LAYER_USED', 1),
 49        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 50        ('512', "512 px", "", 'HAND', 3),
 51        ('1024', "1024 px", "", 'FILE_TICK', 4),
 52        ('2048', "2048 px", "", 'ERROR', 5),
 53        ('4096', "4096 px", "", 'CANCEL', 6),
 54        ]
 55    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 56    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
 57    image_color = bpy.props.FloatVectorProperty(name="色", default=(1, 1, 1, 1), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=4)
 58
 59    @classmethod
 60    def poll(cls, context):
 61        if len(context.selected_objects) != 1:
 62            return False
 63        ob = context.active_object
 64        if ob:
 65            if ob.type == 'MESH':
 66                me = ob.data
 67                if len(me.uv_layers):
 68                    return True
 69        return False
 70
 71    def invoke(self, context, event):
 72        ob = context.active_object
 73        self.image_name = ob.name + " Bake"
 74        return context.window_manager.invoke_props_dialog(self)
 75
 76    def draw(self, context):
 77        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
 78        self.layout.prop(self, 'image_name', icon='SORTALPHA')
 79        row = self.layout.row(align=True)
 80        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
 81        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
 82        self.layout.prop(self, 'image_color', icon='COLOR')
 83
 84    def execute(self, context):
 85        ob = context.active_object
 86        me = ob.data
 87        ob.hide_render = False
 88
 89        image_width, image_height = int(self.image_width), int(self.image_height)
 90
 91        if self.image_name in context.blend_data.images:
 92            img = context.blend_data.images[self.image_name]
 93        else:
 94            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 95
 96        area = common.get_request_area(context, 'IMAGE_EDITOR')
 97        common.set_area_space_attr(area, 'image', img)
 98
 99        img.generated_color = self.image_color
100
101        for elem in me.uv_textures.active.data:
102            elem.image = img
103
104        return {'FINISHED'}
bl_idname = 'object.add_bake_image'
bl_label = 'ベイク用の画像を作成'
bl_description = 'アクティブオブジェクトに素早くベイク用の空の画像を用意します'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
image_color: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '色', 'default': (1, 1, 1, 1), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 4, 'attr': 'image_color'}> = <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '色', 'default': (1, 1, 1, 1), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 4, 'attr': 'image_color'}>
@classmethod
def poll(cls, context):
59    @classmethod
60    def poll(cls, context):
61        if len(context.selected_objects) != 1:
62            return False
63        ob = context.active_object
64        if ob:
65            if ob.type == 'MESH':
66                me = ob.data
67                if len(me.uv_layers):
68                    return True
69        return False
def invoke(self, context, event):
71    def invoke(self, context, event):
72        ob = context.active_object
73        self.image_name = ob.name + " Bake"
74        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
76    def draw(self, context):
77        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
78        self.layout.prop(self, 'image_name', icon='SORTALPHA')
79        row = self.layout.row(align=True)
80        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
81        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
82        self.layout.prop(self, 'image_color', icon='COLOR')
def execute(self, context):
 84    def execute(self, context):
 85        ob = context.active_object
 86        me = ob.data
 87        ob.hide_render = False
 88
 89        image_width, image_height = int(self.image_width), int(self.image_height)
 90
 91        if self.image_name in context.blend_data.images:
 92            img = context.blend_data.images[self.image_name]
 93        else:
 94            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
 95
 96        area = common.get_request_area(context, 'IMAGE_EDITOR')
 97        common.set_area_space_attr(area, 'image', img)
 98
 99        img.generated_color = self.image_color
100
101        for elem in me.uv_textures.active.data:
102            elem.image = img
103
104        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_add_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_ao_bake_image(bpy_types.Operator):
107@compat.BlRegister()
108class CNV_OT_quick_ao_bake_image(bpy.types.Operator):
109    bl_idname = 'object.quick_ao_bake_image'
110    bl_label = "AO・ベイク"
111    bl_description = "アクティブオブジェクトに素早くAOをベイクします"
112    bl_options = {'REGISTER', 'UNDO'}
113
114    image_name = bpy.props.StringProperty(name="画像名")
115    items = [
116        ('128', "128 px", "", 'LAYER_USED', 1),
117        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
118        ('512', "512 px", "", 'HAND', 3),
119        ('1024', "1024 px", "", 'FILE_TICK', 4),
120        ('2048', "2048 px", "", 'ERROR', 5),
121        ('4096', "4096 px", "", 'CANCEL', 6),
122    ]
123    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
124    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
125
126    items = [
127        ('RAYTRACE', "レイトレース", "", 'BRUSH_TEXFILL', 1),
128        ('APPROXIMATE', "近似(AAO)", "", 'MATSPHERE', 2),
129    ]
130    ao_gather_method = bpy.props.EnumProperty(items=items, name="処理方法", default='RAYTRACE')
131    ao_samples = bpy.props.IntProperty(name="精度", default=20, min=1, max=50, soft_min=1, soft_max=50)
132    ao_hide_other = bpy.props.BoolProperty(name="他オブジェクトの影響を受けない", default=True)
133
134    @classmethod
135    def poll(cls, context):
136        if len(context.selected_objects) != 1:
137            return False
138        ob = context.active_object
139        if ob:
140            if ob.type == 'MESH':
141                me = ob.data
142                if len(me.uv_layers):
143                    return True
144        return False
145
146    def invoke(self, context, event):
147        ob = context.active_object
148        self.image_name = ob.name + " AO Bake"
149        return context.window_manager.invoke_props_dialog(self)
150
151    def draw(self, context):
152        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
153        self.layout.prop(self, 'image_name', icon='SORTALPHA')
154        row = self.layout.row(align=True)
155        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
156        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
157        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
158        self.layout.prop(self, 'ao_gather_method', icon='NODETREE', expand=True)
159        self.layout.prop(self, 'ao_samples', icon='ANIM_DATA')
160        self.layout.prop(self, 'ao_hide_other', icon='VISIBLE_IPO_OFF')
161
162    def execute(self, context):
163        ob = context.active_object
164        me = ob.data
165        ob.hide_render = False
166
167        image_width, image_height = int(self.image_width), int(self.image_height)
168
169        if self.image_name in context.blend_data.images:
170            img = context.blend_data.images[self.image_name]
171        else:
172            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
173
174        area = common.get_request_area(context, 'IMAGE_EDITOR')
175        common.set_area_space_attr(area, 'image', img)
176
177        for elem in me.uv_textures.active.data:
178            elem.image = img
179
180        context.scene.world.light_settings.gather_method = self.ao_gather_method
181        context.scene.world.light_settings.samples = self.ao_samples
182
183        if self.ao_hide_other: hide_render_restore = common.hide_render_restore()
184
185        context.scene.render.bake_type = 'AO'
186        context.scene.render.use_bake_normalize = True
187        context.scene.render.use_bake_selected_to_active = False
188        bpy.ops.object.bake_image()
189
190        if self.ao_hide_other: hide_render_restore.restore()
191
192        return {'FINISHED'}
bl_idname = 'object.quick_ao_bake_image'
bl_label = 'AO・ベイク'
bl_description = 'アクティブオブジェクトに素早くAOをベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('RAYTRACE', 'レイトレース', '', 'BRUSH_TEXFILL', 1), ('APPROXIMATE', '近似(AAO)', '', 'MATSPHERE', 2)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
ao_gather_method: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('RAYTRACE', 'レイトレース', '', 'BRUSH_TEXFILL', 1), ('APPROXIMATE', '近似(AAO)', '', 'MATSPHERE', 2)], 'name': '処理方法', 'default': 'RAYTRACE', 'attr': 'ao_gather_method'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('RAYTRACE', 'レイトレース', '', 'BRUSH_TEXFILL', 1), ('APPROXIMATE', '近似(AAO)', '', 'MATSPHERE', 2)], 'name': '処理方法', 'default': 'RAYTRACE', 'attr': 'ao_gather_method'}>
ao_samples: <_PropertyDeferred, <built-in function IntProperty>, {'name': '精度', 'default': 20, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'ao_samples'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': '精度', 'default': 20, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'ao_samples'}>
ao_hide_other: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '他オブジェクトの影響を受けない', 'default': True, 'attr': 'ao_hide_other'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '他オブジェクトの影響を受けない', 'default': True, 'attr': 'ao_hide_other'}>
@classmethod
def poll(cls, context):
134    @classmethod
135    def poll(cls, context):
136        if len(context.selected_objects) != 1:
137            return False
138        ob = context.active_object
139        if ob:
140            if ob.type == 'MESH':
141                me = ob.data
142                if len(me.uv_layers):
143                    return True
144        return False
def invoke(self, context, event):
146    def invoke(self, context, event):
147        ob = context.active_object
148        self.image_name = ob.name + " AO Bake"
149        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
151    def draw(self, context):
152        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
153        self.layout.prop(self, 'image_name', icon='SORTALPHA')
154        row = self.layout.row(align=True)
155        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
156        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
157        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
158        self.layout.prop(self, 'ao_gather_method', icon='NODETREE', expand=True)
159        self.layout.prop(self, 'ao_samples', icon='ANIM_DATA')
160        self.layout.prop(self, 'ao_hide_other', icon='VISIBLE_IPO_OFF')
def execute(self, context):
162    def execute(self, context):
163        ob = context.active_object
164        me = ob.data
165        ob.hide_render = False
166
167        image_width, image_height = int(self.image_width), int(self.image_height)
168
169        if self.image_name in context.blend_data.images:
170            img = context.blend_data.images[self.image_name]
171        else:
172            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
173
174        area = common.get_request_area(context, 'IMAGE_EDITOR')
175        common.set_area_space_attr(area, 'image', img)
176
177        for elem in me.uv_textures.active.data:
178            elem.image = img
179
180        context.scene.world.light_settings.gather_method = self.ao_gather_method
181        context.scene.world.light_settings.samples = self.ao_samples
182
183        if self.ao_hide_other: hide_render_restore = common.hide_render_restore()
184
185        context.scene.render.bake_type = 'AO'
186        context.scene.render.use_bake_normalize = True
187        context.scene.render.use_bake_selected_to_active = False
188        bpy.ops.object.bake_image()
189
190        if self.ao_hide_other: hide_render_restore.restore()
191
192        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_ao_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_dirty_bake_image(bpy_types.Operator):
195@compat.BlRegister()
196class CNV_OT_quick_dirty_bake_image(bpy.types.Operator):
197    bl_idname = 'object.quick_dirty_bake_image'
198    bl_label = "擬似AO・ベイク"
199    bl_description = "アクティブオブジェクトに素早く擬似AOをベイクします"
200    bl_options = {'REGISTER', 'UNDO'}
201
202    image_name = bpy.props.StringProperty(name="画像名")
203    items = [
204        ('128', "128 px", "", 'LAYER_USED', 1),
205        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
206        ('512', "512 px", "", 'HAND', 3),
207        ('1024', "1024 px", "", 'FILE_TICK', 4),
208        ('2048', "2048 px", "", 'ERROR', 5),
209        ('4096', "4096 px", "", 'CANCEL', 6),
210        ]
211    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
212    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
213
214    blur_strength = bpy.props.FloatProperty(name="ブラー強度", default=1, min=0.01, max=1, soft_min=0.01, soft_max=1, step=10, precision=2)
215    blur_iterations = bpy.props.IntProperty(name="ブラー反復度", default=1, min=0, max=40, soft_min=0, soft_max=40)
216    clean_angle = bpy.props.FloatProperty(name="ハイライト角度", default=3.14159, min=0, max=3.14159, soft_min=0, soft_max=3.14159, step=3, precision=0, subtype='ANGLE')
217    dirt_angle = bpy.props.FloatProperty(name="擬似AO角度", default=0, min=0, max=3.14159, soft_min=0, soft_max=3.14159, step=3, precision=0, subtype='ANGLE')
218    dirt_only = bpy.props.BoolProperty(name="擬似AOのみ", default=True)
219
220    @classmethod
221    def poll(cls, context):
222        if len(context.selected_objects) != 1:
223            return False
224        ob = context.active_object
225        if ob:
226            if ob.type == 'MESH':
227                me = ob.data
228                if len(me.uv_layers):
229                    return True
230        return False
231
232    def invoke(self, context, event):
233        ob = context.active_object
234        self.image_name = ob.name + " Dirty AO Bake"
235        return context.window_manager.invoke_props_dialog(self)
236
237    def draw(self, context):
238        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
239        self.layout.prop(self, 'image_name', icon='SORTALPHA')
240        row = self.layout.row(align=True)
241        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
242        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
243        self.layout.label(text="擬似AO設定", icon='BRUSH_TEXFILL')
244        row = self.layout.row(align=True)
245        row.prop(self, 'blur_strength', icon='NONE', slider=True)
246        row.prop(self, 'blur_iterations', icon='NONE')
247        self.layout.prop(self, 'clean_angle', icon='NONE', slider=True)
248        row = self.layout.row(align=True)
249        row.prop(self, 'dirt_angle', icon='NONE', slider=True)
250        row.prop(self, 'dirt_only', icon='FILE_TICK')
251
252    def execute(self, context):
253        ob = context.active_object
254        me = ob.data
255        compat.set_select(ob, False)
256        ob.hide_render = False
257
258        image_width, image_height = int(self.image_width), int(self.image_height)
259
260        if self.image_name in context.blend_data.images:
261            img = context.blend_data.images[self.image_name]
262        else:
263            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
264
265        area = common.get_request_area(context, 'IMAGE_EDITOR')
266        common.set_area_space_attr(area, 'image', img)
267        for elem in me.uv_textures.active.data:
268            elem.image = img
269
270        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
271        temp_ob = context.blend_data.objects.new("quick_dirty_bake_image_temp", temp_me)
272        compat.link(context.scene, temp_ob)
273        for vc in temp_me.vertex_colors:
274            temp_me.vertex_colors.remove(vc)
275        temp_vertex_color = temp_me.vertex_colors.new(name="quick_dirty_bake_image_temp")
276        compat.set_active(context, temp_ob)
277        compat.set_select(temp_ob, True)
278
279        override = context.copy()
280        override['object'] = temp_ob
281        bpy.ops.paint.vertex_color_dirt(override, blur_strength=self.blur_strength, blur_iterations=self.blur_iterations, clean_angle=self.clean_angle, dirt_angle=self.dirt_angle, dirt_only=self.dirt_only)
282
283        temp_ob.update_tag(refresh={'OBJECT', 'DATA'})
284        context.scene.render.bake_type = 'VERTEX_COLORS'
285        context.scene.render.use_bake_selected_to_active = False
286        bpy.ops.object.bake_image(context.copy())
287
288        common.remove_data([temp_me, temp_ob])
289        compat.set_active(context, ob)
290        compat.set_select(ob, True)
291
292        return {'FINISHED'}
bl_idname = 'object.quick_dirty_bake_image'
bl_label = '擬似AO・ベイク'
bl_description = 'アクティブオブジェクトに素早く擬似AOをベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
blur_strength: <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'ブラー強度', 'default': 1, 'min': 0.01, 'max': 1, 'soft_min': 0.01, 'soft_max': 1, 'step': 10, 'precision': 2, 'attr': 'blur_strength'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'ブラー強度', 'default': 1, 'min': 0.01, 'max': 1, 'soft_min': 0.01, 'soft_max': 1, 'step': 10, 'precision': 2, 'attr': 'blur_strength'}>
blur_iterations: <_PropertyDeferred, <built-in function IntProperty>, {'name': 'ブラー反復度', 'default': 1, 'min': 0, 'max': 40, 'soft_min': 0, 'soft_max': 40, 'attr': 'blur_iterations'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': 'ブラー反復度', 'default': 1, 'min': 0, 'max': 40, 'soft_min': 0, 'soft_max': 40, 'attr': 'blur_iterations'}>
clean_angle: <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'ハイライト角度', 'default': 3.14159, 'min': 0, 'max': 3.14159, 'soft_min': 0, 'soft_max': 3.14159, 'step': 3, 'precision': 0, 'subtype': 'ANGLE', 'attr': 'clean_angle'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'ハイライト角度', 'default': 3.14159, 'min': 0, 'max': 3.14159, 'soft_min': 0, 'soft_max': 3.14159, 'step': 3, 'precision': 0, 'subtype': 'ANGLE', 'attr': 'clean_angle'}>
dirt_angle: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '擬似AO角度', 'default': 0, 'min': 0, 'max': 3.14159, 'soft_min': 0, 'soft_max': 3.14159, 'step': 3, 'precision': 0, 'subtype': 'ANGLE', 'attr': 'dirt_angle'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '擬似AO角度', 'default': 0, 'min': 0, 'max': 3.14159, 'soft_min': 0, 'soft_max': 3.14159, 'step': 3, 'precision': 0, 'subtype': 'ANGLE', 'attr': 'dirt_angle'}>
dirt_only: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '擬似AOのみ', 'default': True, 'attr': 'dirt_only'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '擬似AOのみ', 'default': True, 'attr': 'dirt_only'}>
@classmethod
def poll(cls, context):
220    @classmethod
221    def poll(cls, context):
222        if len(context.selected_objects) != 1:
223            return False
224        ob = context.active_object
225        if ob:
226            if ob.type == 'MESH':
227                me = ob.data
228                if len(me.uv_layers):
229                    return True
230        return False
def invoke(self, context, event):
232    def invoke(self, context, event):
233        ob = context.active_object
234        self.image_name = ob.name + " Dirty AO Bake"
235        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
237    def draw(self, context):
238        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
239        self.layout.prop(self, 'image_name', icon='SORTALPHA')
240        row = self.layout.row(align=True)
241        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
242        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
243        self.layout.label(text="擬似AO設定", icon='BRUSH_TEXFILL')
244        row = self.layout.row(align=True)
245        row.prop(self, 'blur_strength', icon='NONE', slider=True)
246        row.prop(self, 'blur_iterations', icon='NONE')
247        self.layout.prop(self, 'clean_angle', icon='NONE', slider=True)
248        row = self.layout.row(align=True)
249        row.prop(self, 'dirt_angle', icon='NONE', slider=True)
250        row.prop(self, 'dirt_only', icon='FILE_TICK')
def execute(self, context):
252    def execute(self, context):
253        ob = context.active_object
254        me = ob.data
255        compat.set_select(ob, False)
256        ob.hide_render = False
257
258        image_width, image_height = int(self.image_width), int(self.image_height)
259
260        if self.image_name in context.blend_data.images:
261            img = context.blend_data.images[self.image_name]
262        else:
263            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
264
265        area = common.get_request_area(context, 'IMAGE_EDITOR')
266        common.set_area_space_attr(area, 'image', img)
267        for elem in me.uv_textures.active.data:
268            elem.image = img
269
270        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
271        temp_ob = context.blend_data.objects.new("quick_dirty_bake_image_temp", temp_me)
272        compat.link(context.scene, temp_ob)
273        for vc in temp_me.vertex_colors:
274            temp_me.vertex_colors.remove(vc)
275        temp_vertex_color = temp_me.vertex_colors.new(name="quick_dirty_bake_image_temp")
276        compat.set_active(context, temp_ob)
277        compat.set_select(temp_ob, True)
278
279        override = context.copy()
280        override['object'] = temp_ob
281        bpy.ops.paint.vertex_color_dirt(override, blur_strength=self.blur_strength, blur_iterations=self.blur_iterations, clean_angle=self.clean_angle, dirt_angle=self.dirt_angle, dirt_only=self.dirt_only)
282
283        temp_ob.update_tag(refresh={'OBJECT', 'DATA'})
284        context.scene.render.bake_type = 'VERTEX_COLORS'
285        context.scene.render.use_bake_selected_to_active = False
286        bpy.ops.object.bake_image(context.copy())
287
288        common.remove_data([temp_me, temp_ob])
289        compat.set_active(context, ob)
290        compat.set_select(ob, True)
291
292        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_dirty_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_hemi_bake_image(bpy_types.Operator):
295@compat.BlRegister()
296class CNV_OT_quick_hemi_bake_image(bpy.types.Operator):
297    bl_idname = 'object.quick_hemi_bake_image'
298    bl_label = "ヘミライト・ベイク"
299    bl_description = "アクティブオブジェクトに素早くヘミライトの陰をベイクします"
300    bl_options = {'REGISTER', 'UNDO'}
301
302    image_name = bpy.props.StringProperty(name="画像名")
303    items = [
304        ('128', "128 px", "", 'LAYER_USED', 1),
305        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
306        ('512', "512 px", "", 'HAND', 3),
307        ('1024', "1024 px", "", 'FILE_TICK', 4),
308        ('2048', "2048 px", "", 'ERROR', 5),
309        ('4096', "4096 px", "", 'CANCEL', 6),
310        ]
311    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
312    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
313
314    lamp_energy = bpy.props.FloatProperty(name="光の強さ", default=1, min=0, max=2, soft_min=0, soft_max=2, step=50, precision=2)
315
316    use_ao = bpy.props.BoolProperty(name="AOを使用", default=False)
317    ao_samples = bpy.props.IntProperty(name="AOの精度", default=20, min=1, max=50, soft_min=1, soft_max=50)
318    ao_hide_other = bpy.props.BoolProperty(name="他オブジェクトの影響を受けない", default=True)
319
320    @classmethod
321    def poll(cls, context):
322        if len(context.selected_objects) != 1:
323            return False
324        ob = context.active_object
325        if ob:
326            if ob.type == 'MESH':
327                me = ob.data
328                if len(me.uv_layers):
329                    return True
330        return False
331
332    def invoke(self, context, event):
333        ob = context.active_object
334        self.image_name = ob.name + " Hemi Bake"
335        return context.window_manager.invoke_props_dialog(self)
336
337    def draw(self, context):
338        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
339        self.layout.prop(self, 'image_name', icon='SORTALPHA')
340        row = self.layout.row(align=True)
341        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
342        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
343        self.layout.label(text="ヘミライト設定", icon='LAMP_HEMI')
344        self.layout.prop(self, 'lamp_energy', icon='LAMP_POINT', slider=True)
345        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
346        row = self.layout.row(align=True)
347        row.prop(self, 'use_ao', icon='FILE_TICK')
348        row.prop(self, 'ao_samples', icon='ANIM_DATA')
349        self.layout.prop(self, 'ao_hide_other', icon='VISIBLE_IPO_OFF')
350
351    def execute(self, context):
352        ob = context.active_object
353        me = ob.data
354        ob.hide_render = False
355
356        override = context.copy()
357        override['object'] = ob
358
359        image_width, image_height = int(self.image_width), int(self.image_height)
360
361        if self.image_name in context.blend_data.images:
362            img = context.blend_data.images[self.image_name]
363        else:
364            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
365
366        area = common.get_request_area(context, 'IMAGE_EDITOR')
367        common.set_area_space_attr(area, 'image', img)
368        for elem in me.uv_textures.active.data:
369            elem.image = img
370
371        if self.ao_hide_other:
372            hide_render_restore = common.hide_render_restore()
373        material_restore = common.material_restore(ob)
374
375        bpy.ops.object.material_slot_add(override)
376        temp_mate = context.blend_data.materials.new("quick_hemi_bake_image_temp")
377        ob.material_slots[0].material = temp_mate
378        temp_mate.diffuse_intensity = 1.0
379        temp_mate.diffuse_color = (1, 1, 1)
380
381        temp_lamp = compat.get_lights(context.blend_data).new("quick_hemi_bake_image_temp", 'HEMI')
382        temp_ob = context.blend_data.objects.new("quick_hemi_bake_image_temp", temp_lamp)
383        compat.link(context.scene, temp_ob)
384        temp_lamp.energy = self.lamp_energy
385
386        context.scene.world.light_settings.use_ambient_occlusion = self.use_ao
387        if self.use_ao:
388            context.scene.world.light_settings.samples = self.ao_samples
389            context.scene.world.light_settings.ao_blend_type = 'MULTIPLY'
390
391        context.scene.render.bake_type = 'FULL'
392        context.scene.render.use_bake_selected_to_active = False
393        bpy.ops.object.bake_image()
394
395        common.remove_data([temp_lamp, temp_ob, temp_mate])
396
397        material_restore.restore()
398        if self.ao_hide_other:
399            hide_render_restore.restore()
400
401        return {'FINISHED'}
bl_idname = 'object.quick_hemi_bake_image'
bl_label = 'ヘミライト・ベイク'
bl_description = 'アクティブオブジェクトに素早くヘミライトの陰をベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
lamp_energy: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '光の強さ', 'default': 1, 'min': 0, 'max': 2, 'soft_min': 0, 'soft_max': 2, 'step': 50, 'precision': 2, 'attr': 'lamp_energy'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '光の強さ', 'default': 1, 'min': 0, 'max': 2, 'soft_min': 0, 'soft_max': 2, 'step': 50, 'precision': 2, 'attr': 'lamp_energy'}>
use_ao: <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'AOを使用', 'default': False, 'attr': 'use_ao'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'AOを使用', 'default': False, 'attr': 'use_ao'}>
ao_samples: <_PropertyDeferred, <built-in function IntProperty>, {'name': 'AOの精度', 'default': 20, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'ao_samples'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': 'AOの精度', 'default': 20, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'ao_samples'}>
ao_hide_other: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '他オブジェクトの影響を受けない', 'default': True, 'attr': 'ao_hide_other'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '他オブジェクトの影響を受けない', 'default': True, 'attr': 'ao_hide_other'}>
@classmethod
def poll(cls, context):
320    @classmethod
321    def poll(cls, context):
322        if len(context.selected_objects) != 1:
323            return False
324        ob = context.active_object
325        if ob:
326            if ob.type == 'MESH':
327                me = ob.data
328                if len(me.uv_layers):
329                    return True
330        return False
def invoke(self, context, event):
332    def invoke(self, context, event):
333        ob = context.active_object
334        self.image_name = ob.name + " Hemi Bake"
335        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
337    def draw(self, context):
338        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
339        self.layout.prop(self, 'image_name', icon='SORTALPHA')
340        row = self.layout.row(align=True)
341        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
342        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
343        self.layout.label(text="ヘミライト設定", icon='LAMP_HEMI')
344        self.layout.prop(self, 'lamp_energy', icon='LAMP_POINT', slider=True)
345        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
346        row = self.layout.row(align=True)
347        row.prop(self, 'use_ao', icon='FILE_TICK')
348        row.prop(self, 'ao_samples', icon='ANIM_DATA')
349        self.layout.prop(self, 'ao_hide_other', icon='VISIBLE_IPO_OFF')
def execute(self, context):
351    def execute(self, context):
352        ob = context.active_object
353        me = ob.data
354        ob.hide_render = False
355
356        override = context.copy()
357        override['object'] = ob
358
359        image_width, image_height = int(self.image_width), int(self.image_height)
360
361        if self.image_name in context.blend_data.images:
362            img = context.blend_data.images[self.image_name]
363        else:
364            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
365
366        area = common.get_request_area(context, 'IMAGE_EDITOR')
367        common.set_area_space_attr(area, 'image', img)
368        for elem in me.uv_textures.active.data:
369            elem.image = img
370
371        if self.ao_hide_other:
372            hide_render_restore = common.hide_render_restore()
373        material_restore = common.material_restore(ob)
374
375        bpy.ops.object.material_slot_add(override)
376        temp_mate = context.blend_data.materials.new("quick_hemi_bake_image_temp")
377        ob.material_slots[0].material = temp_mate
378        temp_mate.diffuse_intensity = 1.0
379        temp_mate.diffuse_color = (1, 1, 1)
380
381        temp_lamp = compat.get_lights(context.blend_data).new("quick_hemi_bake_image_temp", 'HEMI')
382        temp_ob = context.blend_data.objects.new("quick_hemi_bake_image_temp", temp_lamp)
383        compat.link(context.scene, temp_ob)
384        temp_lamp.energy = self.lamp_energy
385
386        context.scene.world.light_settings.use_ambient_occlusion = self.use_ao
387        if self.use_ao:
388            context.scene.world.light_settings.samples = self.ao_samples
389            context.scene.world.light_settings.ao_blend_type = 'MULTIPLY'
390
391        context.scene.render.bake_type = 'FULL'
392        context.scene.render.use_bake_selected_to_active = False
393        bpy.ops.object.bake_image()
394
395        common.remove_data([temp_lamp, temp_ob, temp_mate])
396
397        material_restore.restore()
398        if self.ao_hide_other:
399            hide_render_restore.restore()
400
401        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_hemi_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_shadow_bake_image(bpy_types.Operator):
404@compat.BlRegister()
405class CNV_OT_quick_shadow_bake_image(bpy.types.Operator):
406    bl_idname = 'object.quick_shadow_bake_image'
407    bl_label = "影・ベイク"
408    bl_description = "アクティブオブジェクトに素早く影をベイクします"
409    bl_options = {'REGISTER', 'UNDO'}
410
411    image_name = bpy.props.StringProperty(name="画像名")
412    items = [
413        ('128', "128 px", "", 'LAYER_USED', 1),
414        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
415        ('512', "512 px", "", 'HAND', 3),
416        ('1024', "1024 px", "", 'FILE_TICK', 4),
417        ('2048', "2048 px", "", 'ERROR', 5),
418        ('4096', "4096 px", "", 'CANCEL', 6),
419        ]
420    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
421    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
422
423    lamp_max_angle = bpy.props.FloatProperty(name="光源の最大角度", default=0.5236, min=0, max=1.5708, soft_min=0, soft_max=1.5708, step=100, precision=0, subtype='ANGLE', unit='ROTATION')
424    lamp_count = bpy.props.IntProperty(name="光源の数", default=8, min=1, max=20, soft_min=1, soft_max=20)
425    is_shadow_only = bpy.props.BoolProperty(name="影のみ", default=False)
426
427    @classmethod
428    def poll(cls, context):
429        if not len(context.selected_objects):
430            return False
431        ob = context.active_object
432        if ob:
433            if ob.type == 'MESH':
434                me = ob.data
435                if len(me.uv_layers):
436                    return True
437        return False
438
439    def invoke(self, context, event):
440        self.image_name = context.active_object.name + " Shadow Bake"
441        return context.window_manager.invoke_props_dialog(self)
442
443    def draw(self, context):
444        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
445        self.layout.prop(self, 'image_name', icon='SORTALPHA')
446        row = self.layout.row(align=True)
447        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
448        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
449        self.layout.label(text="光源設定", icon='LAMP_SUN')
450        self.layout.prop(self, 'lamp_max_angle', icon='LAMP_AREA', slider=True)
451        self.layout.prop(self, 'lamp_count', icon='LAMP_POINT')
452        self.layout.prop(self, 'is_shadow_only', icon='IMAGE_ALPHA')
453
454    def execute(self, context):
455        ob = context.active_object
456        me = ob.data
457        ob.hide_render = False
458
459        override = context.copy()
460        override['object'] = ob
461
462        image_width, image_height = int(self.image_width), int(self.image_height)
463
464        if self.image_name in context.blend_data.images:
465            img = context.blend_data.images[self.image_name]
466        else:
467            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
468
469        area = common.get_request_area(context, 'IMAGE_EDITOR')
470        common.set_area_space_attr(area, 'image', img)
471        for elem in me.uv_textures.active.data:
472            elem.image = img
473
474        hide_render_restore = common.hide_render_restore()
475        material_restore = common.material_restore(ob)
476
477        bpy.ops.object.material_slot_add(override)
478        temp_mate = context.blend_data.materials.new("quick_shadow_bake_image_temp")
479        ob.material_slots[0].material = temp_mate
480
481        lights = compat.get_lights(context.blend_data)
482        if self.is_shadow_only:
483            temp_hemi = lights.new("quick_hemi_bake_image_lamp_temp", 'HEMI')
484            temp_hemi_ob = context.blend_data.objects.new("quick_hemi_bake_image_lamp_temp", temp_hemi)
485            compat.link(context.scene, temp_hemi_ob)
486            temp_hemi.energy = 0.00001
487
488        new_lamps = []
489        lamp_count = (self.lamp_count * 2) - 1
490        angle_interval = self.lamp_max_angle / self.lamp_count
491        for x_index in range(lamp_count):
492            x_angle = angle_interval * (x_index - self.lamp_count + 1)
493
494            for y_index in range(lamp_count):
495                y_angle = angle_interval * (y_index - self.lamp_count + 1)
496
497                temp_lamp = lights.new("quick_shadow_bake_image_temp", 'SUN')
498                temp_lamp.shadow_method = 'RAY_SHADOW'
499                temp_lamp_ob = context.blend_data.objects.new("quick_shadow_bake_image_temp", temp_lamp)
500                compat.link(context.scene, temp_lamp_ob)
501                temp_lamp_ob.rotation_mode = 'XYZ'
502                temp_lamp_ob.rotation_euler = mathutils.Euler((x_angle, y_angle, 0), 'XYZ')
503
504                new_lamps.append(temp_lamp)
505                new_lamps.append(temp_lamp_ob)
506
507        context.scene.render.bake_type = 'SHADOW'
508        context.scene.render.use_bake_selected_to_active = False
509        bpy.ops.object.bake_image()
510
511        common.remove_data([temp_mate] + new_lamps)
512        if self.is_shadow_only: common.remove_data([temp_hemi_ob, temp_hemi])
513
514        material_restore.restore()
515        hide_render_restore.restore()
516
517        return {'FINISHED'}
bl_idname = 'object.quick_shadow_bake_image'
bl_label = '影・ベイク'
bl_description = 'アクティブオブジェクトに素早く影をベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
lamp_max_angle: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '光源の最大角度', 'default': 0.5236, 'min': 0, 'max': 1.5708, 'soft_min': 0, 'soft_max': 1.5708, 'step': 100, 'precision': 0, 'subtype': 'ANGLE', 'unit': 'ROTATION', 'attr': 'lamp_max_angle'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '光源の最大角度', 'default': 0.5236, 'min': 0, 'max': 1.5708, 'soft_min': 0, 'soft_max': 1.5708, 'step': 100, 'precision': 0, 'subtype': 'ANGLE', 'unit': 'ROTATION', 'attr': 'lamp_max_angle'}>
lamp_count: <_PropertyDeferred, <built-in function IntProperty>, {'name': '光源の数', 'default': 8, 'min': 1, 'max': 20, 'soft_min': 1, 'soft_max': 20, 'attr': 'lamp_count'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': '光源の数', 'default': 8, 'min': 1, 'max': 20, 'soft_min': 1, 'soft_max': 20, 'attr': 'lamp_count'}>
is_shadow_only: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '影のみ', 'default': False, 'attr': 'is_shadow_only'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '影のみ', 'default': False, 'attr': 'is_shadow_only'}>
@classmethod
def poll(cls, context):
427    @classmethod
428    def poll(cls, context):
429        if not len(context.selected_objects):
430            return False
431        ob = context.active_object
432        if ob:
433            if ob.type == 'MESH':
434                me = ob.data
435                if len(me.uv_layers):
436                    return True
437        return False
def invoke(self, context, event):
439    def invoke(self, context, event):
440        self.image_name = context.active_object.name + " Shadow Bake"
441        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
443    def draw(self, context):
444        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
445        self.layout.prop(self, 'image_name', icon='SORTALPHA')
446        row = self.layout.row(align=True)
447        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
448        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
449        self.layout.label(text="光源設定", icon='LAMP_SUN')
450        self.layout.prop(self, 'lamp_max_angle', icon='LAMP_AREA', slider=True)
451        self.layout.prop(self, 'lamp_count', icon='LAMP_POINT')
452        self.layout.prop(self, 'is_shadow_only', icon='IMAGE_ALPHA')
def execute(self, context):
454    def execute(self, context):
455        ob = context.active_object
456        me = ob.data
457        ob.hide_render = False
458
459        override = context.copy()
460        override['object'] = ob
461
462        image_width, image_height = int(self.image_width), int(self.image_height)
463
464        if self.image_name in context.blend_data.images:
465            img = context.blend_data.images[self.image_name]
466        else:
467            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
468
469        area = common.get_request_area(context, 'IMAGE_EDITOR')
470        common.set_area_space_attr(area, 'image', img)
471        for elem in me.uv_textures.active.data:
472            elem.image = img
473
474        hide_render_restore = common.hide_render_restore()
475        material_restore = common.material_restore(ob)
476
477        bpy.ops.object.material_slot_add(override)
478        temp_mate = context.blend_data.materials.new("quick_shadow_bake_image_temp")
479        ob.material_slots[0].material = temp_mate
480
481        lights = compat.get_lights(context.blend_data)
482        if self.is_shadow_only:
483            temp_hemi = lights.new("quick_hemi_bake_image_lamp_temp", 'HEMI')
484            temp_hemi_ob = context.blend_data.objects.new("quick_hemi_bake_image_lamp_temp", temp_hemi)
485            compat.link(context.scene, temp_hemi_ob)
486            temp_hemi.energy = 0.00001
487
488        new_lamps = []
489        lamp_count = (self.lamp_count * 2) - 1
490        angle_interval = self.lamp_max_angle / self.lamp_count
491        for x_index in range(lamp_count):
492            x_angle = angle_interval * (x_index - self.lamp_count + 1)
493
494            for y_index in range(lamp_count):
495                y_angle = angle_interval * (y_index - self.lamp_count + 1)
496
497                temp_lamp = lights.new("quick_shadow_bake_image_temp", 'SUN')
498                temp_lamp.shadow_method = 'RAY_SHADOW'
499                temp_lamp_ob = context.blend_data.objects.new("quick_shadow_bake_image_temp", temp_lamp)
500                compat.link(context.scene, temp_lamp_ob)
501                temp_lamp_ob.rotation_mode = 'XYZ'
502                temp_lamp_ob.rotation_euler = mathutils.Euler((x_angle, y_angle, 0), 'XYZ')
503
504                new_lamps.append(temp_lamp)
505                new_lamps.append(temp_lamp_ob)
506
507        context.scene.render.bake_type = 'SHADOW'
508        context.scene.render.use_bake_selected_to_active = False
509        bpy.ops.object.bake_image()
510
511        common.remove_data([temp_mate] + new_lamps)
512        if self.is_shadow_only: common.remove_data([temp_hemi_ob, temp_hemi])
513
514        material_restore.restore()
515        hide_render_restore.restore()
516
517        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_shadow_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_side_shadow_bake_image(bpy_types.Operator):
520@compat.BlRegister()
521class CNV_OT_quick_side_shadow_bake_image(bpy.types.Operator):
522    bl_idname = 'object.quick_side_shadow_bake_image'
523    bl_label = "側面陰・ベイク"
524    bl_description = "アクティブオブジェクトに素早く側面陰をベイクします"
525    bl_options = {'REGISTER', 'UNDO'}
526
527    image_name = bpy.props.StringProperty(name="画像名")
528    items = [
529        ('128', "128 px", "", 'LAYER_USED', 1),
530        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
531        ('512', "512 px", "", 'HAND', 3),
532        ('1024', "1024 px", "", 'FILE_TICK', 4),
533        ('2048', "2048 px", "", 'ERROR', 5),
534        ('4096', "4096 px", "", 'CANCEL', 6),
535        ]
536    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
537    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
538
539    is_bipolarization = bpy.props.BoolProperty(name="二極化を有効", default=True)
540    bipolarization_threshold = bpy.props.FloatProperty(name="二極化のしきい値", default=0.5, min=0, max=1, soft_min=0, soft_max=1, step=5, precision=2)
541    bipolarization_blur = bpy.props.FloatProperty(name="二極化のぼかし", default=0.05, min=0, max=1, soft_min=0, soft_max=1, step=1, precision=2)
542
543    @classmethod
544    def poll(cls, context):
545        if len(context.selected_objects) != 1:
546            return False
547        ob = context.active_object
548        if ob:
549            if ob.type == 'MESH':
550                me = ob.data
551                if len(me.uv_layers):
552                    return True
553        return False
554
555    def invoke(self, context, event):
556        self.image_name = context.active_object.name + " SideShade Bake"
557        return context.window_manager.invoke_props_dialog(self)
558
559    def draw(self, context):
560        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
561        self.layout.prop(self, 'image_name', icon='SORTALPHA')
562        row = self.layout.row(align=True)
563        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
564        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
565        self.layout.separator()
566        self.layout.prop(self, 'is_bipolarization', icon='IMAGE_ALPHA')
567        row = self.layout.row(align=True)
568        row.prop(self, 'bipolarization_threshold', icon='NONE', text="しきい値")
569        row.prop(self, 'bipolarization_blur', icon='NONE', text="ぼかし")
570
571    def execute(self, context):
572        ob = context.active_object
573        me = ob.data
574        ob.hide_render = False
575
576        override = context.copy()
577        override['object'] = ob
578
579        image_width, image_height = int(self.image_width), int(self.image_height)
580
581        if self.image_name in context.blend_data.images:
582            img = context.blend_data.images[self.image_name]
583        else:
584            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True, float_buffer=True)
585
586        area = common.get_request_area(context, 'IMAGE_EDITOR')
587        common.set_area_space_attr(area, 'image', img)
588        for elem in me.uv_textures.active.data:
589            elem.image = img
590
591        material_restore = common.material_restore(ob)
592
593        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
594        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
595            data_to.materials = ["Side Shadow"]
596
597        bpy.ops.object.material_slot_add(override)
598        temp_mate = data_to.materials[0]
599        ob.material_slots[0].material = temp_mate
600
601        temp_lamp = compat.get_lights(context.blend_data).new("quick_side_shadow_bake_image_lamp_temp", 'HEMI')
602        temp_lamp_ob = context.blend_data.objects.new("quick_side_shadow_bake_image_lamp_temp", temp_lamp)
603        compat.link(context.scene, temp_lamp_ob)
604
605        pre_scene_camera = context.scene.camera
606        temp_camera = context.blend_data.cameras.new("quick_side_shadow_bake_image_camera_temp")
607        temp_camera_ob = context.blend_data.objects.new("quick_side_shadow_bake_image_camera_temp", temp_camera)
608        compat.link(context.scene, temp_camera_ob)
609        temp_camera_ob.rotation_euler[0] = 1.5708
610        context.scene.camera = temp_camera_ob
611
612        context.scene.world.light_settings.use_ambient_occlusion = False
613
614        context.scene.render.bake_type = 'FULL'
615        context.scene.render.use_bake_selected_to_active = False
616        bpy.ops.object.bake_image()
617
618        common.remove_data([temp_mate, temp_lamp_ob, temp_lamp, temp_camera_ob, temp_camera])
619        context.scene.camera = pre_scene_camera
620
621        material_restore.restore()
622
623        if self.is_bipolarization:
624            img_w, img_h, img_c = img.size[0], img.size[1], img.channels
625            pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
626            min = self.bipolarization_threshold - (self.bipolarization_blur / 2.0)
627            max = self.bipolarization_threshold + (self.bipolarization_blur / 2.0)
628            i = numpy.where(pixels[:,:,:3] <= min)
629            pixels[:,:,:3][i] = 0.0
630            i = numpy.where(max <= pixels[:,:,:3])
631            pixels[:,:,:3][i] = 1.0
632            if 0.0 < max - min:
633                i = numpy.where((min < pixels[:,:,:3]) & (pixels[:,:,:3] < max))
634                pixels[:,:,:3][i] -= min
635                pixels[:,:,:3][i] *= 1.0 / (max - min)
636            img.pixels = pixels.flatten()
637
638        return {'FINISHED'}
bl_idname = 'object.quick_side_shadow_bake_image'
bl_label = '側面陰・ベイク'
bl_description = 'アクティブオブジェクトに素早く側面陰をベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
is_bipolarization: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '二極化を有効', 'default': True, 'attr': 'is_bipolarization'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '二極化を有効', 'default': True, 'attr': 'is_bipolarization'}>
bipolarization_threshold: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '二極化のしきい値', 'default': 0.5, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 5, 'precision': 2, 'attr': 'bipolarization_threshold'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '二極化のしきい値', 'default': 0.5, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 5, 'precision': 2, 'attr': 'bipolarization_threshold'}>
bipolarization_blur: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '二極化のぼかし', 'default': 0.05, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 1, 'precision': 2, 'attr': 'bipolarization_blur'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '二極化のぼかし', 'default': 0.05, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 1, 'precision': 2, 'attr': 'bipolarization_blur'}>
@classmethod
def poll(cls, context):
543    @classmethod
544    def poll(cls, context):
545        if len(context.selected_objects) != 1:
546            return False
547        ob = context.active_object
548        if ob:
549            if ob.type == 'MESH':
550                me = ob.data
551                if len(me.uv_layers):
552                    return True
553        return False
def invoke(self, context, event):
555    def invoke(self, context, event):
556        self.image_name = context.active_object.name + " SideShade Bake"
557        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
559    def draw(self, context):
560        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
561        self.layout.prop(self, 'image_name', icon='SORTALPHA')
562        row = self.layout.row(align=True)
563        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
564        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
565        self.layout.separator()
566        self.layout.prop(self, 'is_bipolarization', icon='IMAGE_ALPHA')
567        row = self.layout.row(align=True)
568        row.prop(self, 'bipolarization_threshold', icon='NONE', text="しきい値")
569        row.prop(self, 'bipolarization_blur', icon='NONE', text="ぼかし")
def execute(self, context):
571    def execute(self, context):
572        ob = context.active_object
573        me = ob.data
574        ob.hide_render = False
575
576        override = context.copy()
577        override['object'] = ob
578
579        image_width, image_height = int(self.image_width), int(self.image_height)
580
581        if self.image_name in context.blend_data.images:
582            img = context.blend_data.images[self.image_name]
583        else:
584            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True, float_buffer=True)
585
586        area = common.get_request_area(context, 'IMAGE_EDITOR')
587        common.set_area_space_attr(area, 'image', img)
588        for elem in me.uv_textures.active.data:
589            elem.image = img
590
591        material_restore = common.material_restore(ob)
592
593        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
594        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
595            data_to.materials = ["Side Shadow"]
596
597        bpy.ops.object.material_slot_add(override)
598        temp_mate = data_to.materials[0]
599        ob.material_slots[0].material = temp_mate
600
601        temp_lamp = compat.get_lights(context.blend_data).new("quick_side_shadow_bake_image_lamp_temp", 'HEMI')
602        temp_lamp_ob = context.blend_data.objects.new("quick_side_shadow_bake_image_lamp_temp", temp_lamp)
603        compat.link(context.scene, temp_lamp_ob)
604
605        pre_scene_camera = context.scene.camera
606        temp_camera = context.blend_data.cameras.new("quick_side_shadow_bake_image_camera_temp")
607        temp_camera_ob = context.blend_data.objects.new("quick_side_shadow_bake_image_camera_temp", temp_camera)
608        compat.link(context.scene, temp_camera_ob)
609        temp_camera_ob.rotation_euler[0] = 1.5708
610        context.scene.camera = temp_camera_ob
611
612        context.scene.world.light_settings.use_ambient_occlusion = False
613
614        context.scene.render.bake_type = 'FULL'
615        context.scene.render.use_bake_selected_to_active = False
616        bpy.ops.object.bake_image()
617
618        common.remove_data([temp_mate, temp_lamp_ob, temp_lamp, temp_camera_ob, temp_camera])
619        context.scene.camera = pre_scene_camera
620
621        material_restore.restore()
622
623        if self.is_bipolarization:
624            img_w, img_h, img_c = img.size[0], img.size[1], img.channels
625            pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
626            min = self.bipolarization_threshold - (self.bipolarization_blur / 2.0)
627            max = self.bipolarization_threshold + (self.bipolarization_blur / 2.0)
628            i = numpy.where(pixels[:,:,:3] <= min)
629            pixels[:,:,:3][i] = 0.0
630            i = numpy.where(max <= pixels[:,:,:3])
631            pixels[:,:,:3][i] = 1.0
632            if 0.0 < max - min:
633                i = numpy.where((min < pixels[:,:,:3]) & (pixels[:,:,:3] < max))
634                pixels[:,:,:3][i] -= min
635                pixels[:,:,:3][i] *= 1.0 / (max - min)
636            img.pixels = pixels.flatten()
637
638        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_side_shadow_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_gradation_bake_image(bpy_types.Operator):
641@compat.BlRegister()
642class CNV_OT_quick_gradation_bake_image(bpy.types.Operator):
643    bl_idname = 'object.quick_gradation_bake_image'
644    bl_label = "グラデーション・ベイク"
645    bl_description = "アクティブオブジェクトに素早くグラデーションをベイクします"
646    bl_options = {'REGISTER', 'UNDO'}
647
648    image_name = bpy.props.StringProperty(name="画像名")
649    items = [
650        ('128', "128 px", "", 'LAYER_USED', 1),
651        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
652        ('512', "512 px", "", 'HAND', 3),
653        ('1024', "1024 px", "", 'FILE_TICK', 4),
654        ('2048', "2048 px", "", 'ERROR', 5),
655        ('4096', "4096 px", "", 'CANCEL', 6),
656        ]
657    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
658    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
659
660    @classmethod
661    def poll(cls, context):
662        if len(context.selected_objects) != 1:
663            return False
664        ob = context.active_object
665        if ob:
666            if ob.type == 'MESH':
667                me = ob.data
668                if len(me.uv_layers):
669                    return True
670        return False
671
672    def invoke(self, context, event):
673        self.image_name = context.active_object.name + " Gradation Bake"
674        return context.window_manager.invoke_props_dialog(self)
675
676    def draw(self, context):
677        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
678        self.layout.prop(self, 'image_name', icon='SORTALPHA')
679        row = self.layout.row(align=True)
680        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
681        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
682
683    def execute(self, context):
684        ob = context.active_object
685        me = ob.data
686        ob.hide_render = False
687
688        override = context.copy()
689        override['object'] = ob
690
691        image_width, image_height = int(self.image_width), int(self.image_height)
692
693        if self.image_name in context.blend_data.images:
694            img = context.blend_data.images[self.image_name]
695        else:
696            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
697
698        area = common.get_request_area(context, 'IMAGE_EDITOR')
699        common.set_area_space_attr(area, 'image', img)
700        for elem in me.uv_textures.active.data:
701            elem.image = img
702
703        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
704        zs = [compat.mul(ob.matrix_world, v.co).z for v in temp_me.vertices]
705        zs.sort()
706        me_conter = (zs[0] + zs[-1]) / 2
707        me_height = zs[-1] - zs[0]
708
709        material_restore = common.material_restore(ob)
710
711        bpy.ops.object.material_slot_add(override)
712        temp_mate = context.blend_data.materials.new("quick_gradation_bake_image_temp")
713        ob.material_slots[0].material = temp_mate
714        temp_slot = temp_mate.texture_slots.create(0)
715        temp_tex = context.blend_data.textures.new("quick_gradation_bake_image_temp", 'BLEND')
716        temp_slot.texture = temp_tex
717        temp_tex.use_color_ramp = True
718        temp_slot.mapping_y = 'Z'
719        temp_slot.mapping_z = 'Y'
720        temp_slot.texture_coords = 'GLOBAL'
721        temp_tex.color_ramp.elements[0].color = (0, 0, 0, 1)
722        temp_tex.use_flip_axis = 'VERTICAL'
723        temp_slot.offset[1] = -me_conter
724        temp_slot.scale[1] = 1 / (me_height / 2)
725
726        context.scene.render.bake_type = 'TEXTURE'
727        context.scene.render.use_bake_selected_to_active = False
728        bpy.ops.object.bake_image()
729
730        common.remove_data([temp_me, temp_mate, temp_tex])
731
732        material_restore.restore()
733
734        return {'FINISHED'}
bl_idname = 'object.quick_gradation_bake_image'
bl_label = 'グラデーション・ベイク'
bl_description = 'アクティブオブジェクトに素早くグラデーションをベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
@classmethod
def poll(cls, context):
660    @classmethod
661    def poll(cls, context):
662        if len(context.selected_objects) != 1:
663            return False
664        ob = context.active_object
665        if ob:
666            if ob.type == 'MESH':
667                me = ob.data
668                if len(me.uv_layers):
669                    return True
670        return False
def invoke(self, context, event):
672    def invoke(self, context, event):
673        self.image_name = context.active_object.name + " Gradation Bake"
674        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
676    def draw(self, context):
677        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
678        self.layout.prop(self, 'image_name', icon='SORTALPHA')
679        row = self.layout.row(align=True)
680        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
681        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
def execute(self, context):
683    def execute(self, context):
684        ob = context.active_object
685        me = ob.data
686        ob.hide_render = False
687
688        override = context.copy()
689        override['object'] = ob
690
691        image_width, image_height = int(self.image_width), int(self.image_height)
692
693        if self.image_name in context.blend_data.images:
694            img = context.blend_data.images[self.image_name]
695        else:
696            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
697
698        area = common.get_request_area(context, 'IMAGE_EDITOR')
699        common.set_area_space_attr(area, 'image', img)
700        for elem in me.uv_textures.active.data:
701            elem.image = img
702
703        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
704        zs = [compat.mul(ob.matrix_world, v.co).z for v in temp_me.vertices]
705        zs.sort()
706        me_conter = (zs[0] + zs[-1]) / 2
707        me_height = zs[-1] - zs[0]
708
709        material_restore = common.material_restore(ob)
710
711        bpy.ops.object.material_slot_add(override)
712        temp_mate = context.blend_data.materials.new("quick_gradation_bake_image_temp")
713        ob.material_slots[0].material = temp_mate
714        temp_slot = temp_mate.texture_slots.create(0)
715        temp_tex = context.blend_data.textures.new("quick_gradation_bake_image_temp", 'BLEND')
716        temp_slot.texture = temp_tex
717        temp_tex.use_color_ramp = True
718        temp_slot.mapping_y = 'Z'
719        temp_slot.mapping_z = 'Y'
720        temp_slot.texture_coords = 'GLOBAL'
721        temp_tex.color_ramp.elements[0].color = (0, 0, 0, 1)
722        temp_tex.use_flip_axis = 'VERTICAL'
723        temp_slot.offset[1] = -me_conter
724        temp_slot.scale[1] = 1 / (me_height / 2)
725
726        context.scene.render.bake_type = 'TEXTURE'
727        context.scene.render.use_bake_selected_to_active = False
728        bpy.ops.object.bake_image()
729
730        common.remove_data([temp_me, temp_mate, temp_tex])
731
732        material_restore.restore()
733
734        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_gradation_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_metal_bake_image(bpy_types.Operator):
737@compat.BlRegister()
738class CNV_OT_quick_metal_bake_image(bpy.types.Operator):
739    bl_idname = 'object.quick_metal_bake_image'
740    bl_label = "金属・ベイク"
741    bl_description = "アクティブオブジェクトに素早く金属風にベイクします"
742    bl_options = {'REGISTER', 'UNDO'}
743
744    image_name = bpy.props.StringProperty(name="画像名")
745    items = [
746        ('128', "128 px", "", 'LAYER_USED', 1),
747        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
748        ('512', "512 px", "", 'HAND', 3),
749        ('1024', "1024 px", "", 'FILE_TICK', 4),
750        ('2048', "2048 px", "", 'ERROR', 5),
751        ('4096', "4096 px", "", 'CANCEL', 6),
752        ]
753    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
754    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
755
756    mate_color = bpy.props.FloatVectorProperty(name="色", default=(0.22, 0.22, 0.22), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR')
757    environment_strength = bpy.props.FloatProperty(name="映り込み強さ", default=1, min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2)
758    highlight_strength = bpy.props.FloatProperty(name="ハイライト強さ", default=0.5, min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2)
759
760    @classmethod
761    def poll(cls, context):
762        if len(context.selected_objects) != 1:
763            return False
764        ob = context.active_object
765        if ob:
766            if ob.type == 'MESH':
767                me = ob.data
768                if len(me.uv_layers):
769                    return True
770        return False
771
772    def invoke(self, context, event):
773        self.image_name = context.active_object.name + " Metal Bake"
774        return context.window_manager.invoke_props_dialog(self)
775
776    def draw(self, context):
777        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
778        self.layout.prop(self, 'image_name', icon='SORTALPHA')
779        row = self.layout.row(align=True)
780        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
781        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
782        self.layout.label(text="金属設定", icon=compat.icon('BRUSH_SOFTEN'))
783        self.layout.prop(self, 'mate_color', icon='COLOR')
784        row = self.layout.row(align=True)
785        row.prop(self, 'environment_strength', icon=compat.icon('BRUSH_SOFTEN'), slider=True)
786        row.prop(self, 'highlight_strength', icon='BRUSH_TEXFILL', slider=True)
787
788    def execute(self, context):
789        ob = context.active_object
790        me = ob.data
791        ob.hide_render = False
792
793        override = context.copy()
794        override['object'] = ob
795
796        image_width, image_height = int(self.image_width), int(self.image_height)
797
798        if self.image_name in context.blend_data.images:
799            img = context.blend_data.images[self.image_name]
800        else:
801            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
802
803        area = common.get_request_area(context, 'IMAGE_EDITOR')
804        common.set_area_space_attr(area, 'image', img)
805        for elem in me.uv_textures.active.data:
806            elem.image = img
807
808        hide_render_restore = common.hide_render_restore()
809        material_restore = common.material_restore(ob)
810
811        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
812        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
813            data_to.materials = ["Metal"]
814
815        bpy.ops.object.material_slot_add(override)
816        temp_mate = data_to.materials[0]
817        ob.material_slots[0].material = temp_mate
818        temp_mate.diffuse_color = self.mate_color[:]
819        temp_mate.texture_slots[0].diffuse_color_factor = self.environment_strength
820        temp_mate.node_tree.nodes["Mix.001"].inputs[0].default_value = 1.0 - self.highlight_strength
821
822        temp_lamp = compat.getlights(context.blend_data).new("quick_metal_bake_image_lamp_temp", 'HEMI')
823        temp_lamp_ob = context.blend_data.objects.new("quick_metal_bake_image_lamp_temp", temp_lamp)
824        compat.link(context.scene, temp_lamp_ob)
825        #temp_lamp.energy = self.lamp_energy
826
827        pre_scene_camera = context.scene.camera
828        temp_camera = context.blend_data.cameras.new("quick_metal_bake_image_camera_temp")
829        temp_camera_ob = context.blend_data.objects.new("quick_metal_bake_image_camera_temp", temp_camera)
830        compat.link(context.scene, temp_camera_ob)
831        temp_camera_ob.rotation_euler[0] = 1.5708
832        context.scene.camera = temp_camera_ob
833
834        context.scene.world.light_settings.use_ambient_occlusion = False
835
836        context.scene.render.bake_type = 'FULL'
837        context.scene.render.use_bake_selected_to_active = False
838        bpy.ops.object.bake_image()
839
840        common.remove_data([temp_mate, temp_lamp_ob, temp_lamp, temp_camera_ob, temp_camera])
841        context.scene.camera = pre_scene_camera
842
843        material_restore.restore()
844        hide_render_restore.restore()
845
846        return {'FINISHED'}
bl_idname = 'object.quick_metal_bake_image'
bl_label = '金属・ベイク'
bl_description = 'アクティブオブジェクトに素早く金属風にベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
mate_color: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '色', 'default': (0.22, 0.22, 0.22), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'attr': 'mate_color'}> = <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '色', 'default': (0.22, 0.22, 0.22), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'attr': 'mate_color'}>
environment_strength: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '映り込み強さ', 'default': 1, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'attr': 'environment_strength'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '映り込み強さ', 'default': 1, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'attr': 'environment_strength'}>
highlight_strength: <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'ハイライト強さ', 'default': 0.5, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'attr': 'highlight_strength'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'ハイライト強さ', 'default': 0.5, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'attr': 'highlight_strength'}>
@classmethod
def poll(cls, context):
760    @classmethod
761    def poll(cls, context):
762        if len(context.selected_objects) != 1:
763            return False
764        ob = context.active_object
765        if ob:
766            if ob.type == 'MESH':
767                me = ob.data
768                if len(me.uv_layers):
769                    return True
770        return False
def invoke(self, context, event):
772    def invoke(self, context, event):
773        self.image_name = context.active_object.name + " Metal Bake"
774        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
776    def draw(self, context):
777        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
778        self.layout.prop(self, 'image_name', icon='SORTALPHA')
779        row = self.layout.row(align=True)
780        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
781        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
782        self.layout.label(text="金属設定", icon=compat.icon('BRUSH_SOFTEN'))
783        self.layout.prop(self, 'mate_color', icon='COLOR')
784        row = self.layout.row(align=True)
785        row.prop(self, 'environment_strength', icon=compat.icon('BRUSH_SOFTEN'), slider=True)
786        row.prop(self, 'highlight_strength', icon='BRUSH_TEXFILL', slider=True)
def execute(self, context):
788    def execute(self, context):
789        ob = context.active_object
790        me = ob.data
791        ob.hide_render = False
792
793        override = context.copy()
794        override['object'] = ob
795
796        image_width, image_height = int(self.image_width), int(self.image_height)
797
798        if self.image_name in context.blend_data.images:
799            img = context.blend_data.images[self.image_name]
800        else:
801            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
802
803        area = common.get_request_area(context, 'IMAGE_EDITOR')
804        common.set_area_space_attr(area, 'image', img)
805        for elem in me.uv_textures.active.data:
806            elem.image = img
807
808        hide_render_restore = common.hide_render_restore()
809        material_restore = common.material_restore(ob)
810
811        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
812        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
813            data_to.materials = ["Metal"]
814
815        bpy.ops.object.material_slot_add(override)
816        temp_mate = data_to.materials[0]
817        ob.material_slots[0].material = temp_mate
818        temp_mate.diffuse_color = self.mate_color[:]
819        temp_mate.texture_slots[0].diffuse_color_factor = self.environment_strength
820        temp_mate.node_tree.nodes["Mix.001"].inputs[0].default_value = 1.0 - self.highlight_strength
821
822        temp_lamp = compat.getlights(context.blend_data).new("quick_metal_bake_image_lamp_temp", 'HEMI')
823        temp_lamp_ob = context.blend_data.objects.new("quick_metal_bake_image_lamp_temp", temp_lamp)
824        compat.link(context.scene, temp_lamp_ob)
825        #temp_lamp.energy = self.lamp_energy
826
827        pre_scene_camera = context.scene.camera
828        temp_camera = context.blend_data.cameras.new("quick_metal_bake_image_camera_temp")
829        temp_camera_ob = context.blend_data.objects.new("quick_metal_bake_image_camera_temp", temp_camera)
830        compat.link(context.scene, temp_camera_ob)
831        temp_camera_ob.rotation_euler[0] = 1.5708
832        context.scene.camera = temp_camera_ob
833
834        context.scene.world.light_settings.use_ambient_occlusion = False
835
836        context.scene.render.bake_type = 'FULL'
837        context.scene.render.use_bake_selected_to_active = False
838        bpy.ops.object.bake_image()
839
840        common.remove_data([temp_mate, temp_lamp_ob, temp_lamp, temp_camera_ob, temp_camera])
841        context.scene.camera = pre_scene_camera
842
843        material_restore.restore()
844        hide_render_restore.restore()
845
846        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_metal_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_hair_bake_image(bpy_types.Operator):
849@compat.BlRegister()
850class CNV_OT_quick_hair_bake_image(bpy.types.Operator):
851    bl_idname = 'object.quick_hair_bake_image'
852    bl_label = "ヘアー・ベイク"
853    bl_description = "アクティブオブジェクトに素早くCM3D2の髪風のテクスチャをベイクします"
854    bl_options = {'REGISTER', 'UNDO'}
855
856    image_name = bpy.props.StringProperty(name="画像名")
857    items = [
858        ('128', "128 px", "", 'LAYER_USED', 1),
859        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
860        ('512', "512 px", "", 'HAND', 3),
861        ('1024', "1024 px", "", 'FILE_TICK', 4),
862        ('2048', "2048 px", "", 'ERROR', 5),
863        ('4096', "4096 px", "", 'CANCEL', 6),
864        ]
865    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
866    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
867
868    mate_diffuse_color = bpy.props.FloatVectorProperty(name="髪色", default=(1, 1, 1), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=3)
869    mate_angel_ring_factor = bpy.props.FloatProperty(name="天使の輪の強さ", default=0.5, min=0, max=1, soft_min=0, soft_max=1, step=50, precision=2)
870
871    lamp_energy = bpy.props.FloatProperty(name="光の強さ", default=1, min=0, max=2, soft_min=0, soft_max=2, step=50, precision=2)
872
873    use_ao = bpy.props.BoolProperty(name="AOを使用", default=False)
874    ao_samples = bpy.props.IntProperty(name="AOの精度", default=20, min=1, max=50, soft_min=1, soft_max=50)
875    ao_hide_other = bpy.props.BoolProperty(name="他オブジェクトの影響を受けない", default=True)
876
877    @classmethod
878    def poll(cls, context):
879        if len(context.selected_objects) != 1:
880            return False
881        ob = context.active_object
882        if ob:
883            if ob.type == 'MESH':
884                me = ob.data
885                if len(me.uv_layers):
886                    return True
887        return False
888
889    def invoke(self, context, event):
890        ob = context.active_object
891        self.image_name = ob.name + " Hair Bake"
892        return context.window_manager.invoke_props_dialog(self)
893
894    def draw(self, context):
895        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
896        self.layout.prop(self, 'image_name', icon='SORTALPHA')
897        row = self.layout.row(align=True)
898        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
899        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
900        self.layout.label(text="ヘアー設定", icon='PARTICLEMODE')
901        self.layout.prop(self, 'mate_diffuse_color', icon='COLOR')
902        self.layout.prop(self, 'mate_angel_ring_factor', icon='BRUSH_TEXFILL', slider=True)
903        self.layout.label(text="ヘミライト設定", icon='LAMP_HEMI')
904        self.layout.prop(self, 'lamp_energy', icon='LAMP_POINT', slider=True)
905        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
906        row = self.layout.row(align=True)
907        row.prop(self, 'use_ao', icon='FILE_TICK')
908        row.prop(self, 'ao_samples', icon='ANIM_DATA')
909        self.layout.prop(self, 'ao_hide_other', icon=compat.icon('VIS_SEL_01'))
910
911    def execute(self, context):
912        import os.path
913
914        ob = context.active_object
915        me = ob.data
916        ob.hide_render = False
917
918        override = context.copy()
919        override['object'] = ob
920
921        image_width, image_height = int(self.image_width), int(self.image_height)
922
923        if self.image_name in context.blend_data.images:
924            img = context.blend_data.images[self.image_name]
925        else:
926            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
927
928        area = common.get_request_area(context, 'IMAGE_EDITOR')
929        common.set_area_space_attr(area, 'image', img)
930
931        for elem in me.uv_textures.active.data:
932            elem.image = img
933
934        if self.ao_hide_other:
935            hide_render_restore = common.hide_render_restore()
936        material_restore = common.material_restore(ob)
937
938        temp_lamp = compat.get_lights(context.blend_data).new("quick_hemi_bake_image_lamp_temp", 'HEMI')
939        temp_lamp_ob = context.blend_data.objects.new("quick_hemi_bake_image_lamp_temp", temp_lamp)
940        compat.link(context.scene, temp_lamp_ob)
941        temp_lamp.energy = self.lamp_energy
942
943        pre_scene_camera = context.scene.camera
944        temp_camera = context.blend_data.cameras.new("quick_hemi_bake_image_camera_temp")
945        temp_camera_ob = context.blend_data.objects.new("quick_hemi_bake_image_camera_temp", temp_camera)
946        compat.link(context.scene, temp_camera_ob)
947        temp_camera_ob.rotation_euler[0] = 1.5708
948        context.scene.camera = temp_camera_ob
949
950        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
951        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
952            data_to.materials = ["CM3D2 Hair"]
953
954        bpy.ops.object.material_slot_add(override)
955        temp_mate = data_to.materials[0]
956        ob.material_slots[0].material = temp_mate
957
958        temp_mate.diffuse_color = self.mate_diffuse_color
959        temp_mate.node_tree.nodes["mate_angel_ring_factor"].inputs[0].default_value = self.mate_angel_ring_factor
960
961        context.scene.world.light_settings.use_ambient_occlusion = self.use_ao
962        if self.use_ao:
963            context.scene.world.light_settings.samples = self.ao_samples
964            context.scene.world.light_settings.ao_blend_type = 'MULTIPLY'
965
966        context.scene.render.bake_type = 'FULL'
967        context.scene.render.use_bake_selected_to_active = False
968        bpy.ops.object.bake_image()
969
970        temp_tex = temp_mate.texture_slots[0].texture
971
972        common.remove_data([temp_mate, temp_tex, temp_camera_ob, temp_camera, temp_lamp_ob, temp_lamp])
973        context.scene.camera = pre_scene_camera
974
975        material_restore.restore()
976        if self.ao_hide_other:
977            hide_render_restore.restore()
978
979        return {'FINISHED'}
bl_idname = 'object.quick_hair_bake_image'
bl_label = 'ヘアー・ベイク'
bl_description = 'アクティブオブジェクトに素早くCM3D2の髪風のテクスチャをベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
mate_diffuse_color: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '髪色', 'default': (1, 1, 1), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 3, 'attr': 'mate_diffuse_color'}> = <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '髪色', 'default': (1, 1, 1), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 3, 'attr': 'mate_diffuse_color'}>
mate_angel_ring_factor: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '天使の輪の強さ', 'default': 0.5, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 50, 'precision': 2, 'attr': 'mate_angel_ring_factor'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '天使の輪の強さ', 'default': 0.5, 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 50, 'precision': 2, 'attr': 'mate_angel_ring_factor'}>
lamp_energy: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '光の強さ', 'default': 1, 'min': 0, 'max': 2, 'soft_min': 0, 'soft_max': 2, 'step': 50, 'precision': 2, 'attr': 'lamp_energy'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': '光の強さ', 'default': 1, 'min': 0, 'max': 2, 'soft_min': 0, 'soft_max': 2, 'step': 50, 'precision': 2, 'attr': 'lamp_energy'}>
use_ao: <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'AOを使用', 'default': False, 'attr': 'use_ao'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': 'AOを使用', 'default': False, 'attr': 'use_ao'}>
ao_samples: <_PropertyDeferred, <built-in function IntProperty>, {'name': 'AOの精度', 'default': 20, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'ao_samples'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': 'AOの精度', 'default': 20, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'ao_samples'}>
ao_hide_other: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '他オブジェクトの影響を受けない', 'default': True, 'attr': 'ao_hide_other'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '他オブジェクトの影響を受けない', 'default': True, 'attr': 'ao_hide_other'}>
@classmethod
def poll(cls, context):
877    @classmethod
878    def poll(cls, context):
879        if len(context.selected_objects) != 1:
880            return False
881        ob = context.active_object
882        if ob:
883            if ob.type == 'MESH':
884                me = ob.data
885                if len(me.uv_layers):
886                    return True
887        return False
def invoke(self, context, event):
889    def invoke(self, context, event):
890        ob = context.active_object
891        self.image_name = ob.name + " Hair Bake"
892        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
894    def draw(self, context):
895        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
896        self.layout.prop(self, 'image_name', icon='SORTALPHA')
897        row = self.layout.row(align=True)
898        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
899        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
900        self.layout.label(text="ヘアー設定", icon='PARTICLEMODE')
901        self.layout.prop(self, 'mate_diffuse_color', icon='COLOR')
902        self.layout.prop(self, 'mate_angel_ring_factor', icon='BRUSH_TEXFILL', slider=True)
903        self.layout.label(text="ヘミライト設定", icon='LAMP_HEMI')
904        self.layout.prop(self, 'lamp_energy', icon='LAMP_POINT', slider=True)
905        self.layout.label(text="AO設定", icon='BRUSH_TEXFILL')
906        row = self.layout.row(align=True)
907        row.prop(self, 'use_ao', icon='FILE_TICK')
908        row.prop(self, 'ao_samples', icon='ANIM_DATA')
909        self.layout.prop(self, 'ao_hide_other', icon=compat.icon('VIS_SEL_01'))
def execute(self, context):
911    def execute(self, context):
912        import os.path
913
914        ob = context.active_object
915        me = ob.data
916        ob.hide_render = False
917
918        override = context.copy()
919        override['object'] = ob
920
921        image_width, image_height = int(self.image_width), int(self.image_height)
922
923        if self.image_name in context.blend_data.images:
924            img = context.blend_data.images[self.image_name]
925        else:
926            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
927
928        area = common.get_request_area(context, 'IMAGE_EDITOR')
929        common.set_area_space_attr(area, 'image', img)
930
931        for elem in me.uv_textures.active.data:
932            elem.image = img
933
934        if self.ao_hide_other:
935            hide_render_restore = common.hide_render_restore()
936        material_restore = common.material_restore(ob)
937
938        temp_lamp = compat.get_lights(context.blend_data).new("quick_hemi_bake_image_lamp_temp", 'HEMI')
939        temp_lamp_ob = context.blend_data.objects.new("quick_hemi_bake_image_lamp_temp", temp_lamp)
940        compat.link(context.scene, temp_lamp_ob)
941        temp_lamp.energy = self.lamp_energy
942
943        pre_scene_camera = context.scene.camera
944        temp_camera = context.blend_data.cameras.new("quick_hemi_bake_image_camera_temp")
945        temp_camera_ob = context.blend_data.objects.new("quick_hemi_bake_image_camera_temp", temp_camera)
946        compat.link(context.scene, temp_camera_ob)
947        temp_camera_ob.rotation_euler[0] = 1.5708
948        context.scene.camera = temp_camera_ob
949
950        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
951        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
952            data_to.materials = ["CM3D2 Hair"]
953
954        bpy.ops.object.material_slot_add(override)
955        temp_mate = data_to.materials[0]
956        ob.material_slots[0].material = temp_mate
957
958        temp_mate.diffuse_color = self.mate_diffuse_color
959        temp_mate.node_tree.nodes["mate_angel_ring_factor"].inputs[0].default_value = self.mate_angel_ring_factor
960
961        context.scene.world.light_settings.use_ambient_occlusion = self.use_ao
962        if self.use_ao:
963            context.scene.world.light_settings.samples = self.ao_samples
964            context.scene.world.light_settings.ao_blend_type = 'MULTIPLY'
965
966        context.scene.render.bake_type = 'FULL'
967        context.scene.render.use_bake_selected_to_active = False
968        bpy.ops.object.bake_image()
969
970        temp_tex = temp_mate.texture_slots[0].texture
971
972        common.remove_data([temp_mate, temp_tex, temp_camera_ob, temp_camera, temp_lamp_ob, temp_lamp])
973        context.scene.camera = pre_scene_camera
974
975        material_restore.restore()
976        if self.ao_hide_other:
977            hide_render_restore.restore()
978
979        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_hair_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_uv_border_bake_image(bpy_types.Operator):
 982@compat.BlRegister()
 983class CNV_OT_quick_uv_border_bake_image(bpy.types.Operator):
 984    bl_idname = 'object.quick_uv_border_bake_image'
 985    bl_label = "UV縁・ベイク"
 986    bl_description = "アクティブオブジェクトに素早くUVの縁を黒くベイクします"
 987    bl_options = {'REGISTER', 'UNDO'}
 988
 989    image_name = bpy.props.StringProperty(name="画像名")
 990    items = [
 991        ('128', "128 px", "", 'LAYER_USED', 1),
 992        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
 993        ('512', "512 px", "", 'HAND', 3),
 994        ('1024', "1024 px", "", 'FILE_TICK', 4),
 995        ('2048', "2048 px", "", 'ERROR', 5),
 996        ('4096', "4096 px", "", 'CANCEL', 6),
 997        ]
 998    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
 999    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1000
1001    items = [
1002        ('FLAT', "フラット", "", 'IPO_CONSTANT', 1),
1003        ('TENT', "テント", "", 'IPO_LINEAR', 2),
1004        ('QUAD', "二次式", "", 'IPO_QUAD', 3),
1005        ('CUBIC', "三次式", "", 'IPO_CUBIC', 4),
1006        ('GAUSS', "ガウシアン", "", 'HAND', 5),
1007        ('FAST_GAUSS', "高速ガウシアン", "", 'ALIASED', 6),
1008        ('CATROM', "Catrom", "", 'FILE_TICK', 7),
1009        ('MITCH', "Mitch", "", 'FILE_TICK', 8),
1010        ]
1011    blur_type = bpy.props.EnumProperty(items=items, name="ぼかしタイプ", default='GAUSS')
1012    blur_strength = bpy.props.IntProperty(name="ぼかし強度", default=100, min=0, max=1000, soft_min=0, soft_max=1000)
1013    normalize = bpy.props.BoolProperty(name="正規化", default=True)
1014    keep_alpha = bpy.props.BoolProperty(name="余白を透過", default=True)
1015
1016    @classmethod
1017    def poll(cls, context):
1018        if len(context.selected_objects) != 1:
1019            return False
1020        ob = context.active_object
1021        if ob:
1022            if ob.type == 'MESH':
1023                me = ob.data
1024                if len(me.uv_layers):
1025                    return True
1026        return False
1027
1028    def invoke(self, context, event):
1029        ob = context.active_object
1030        self.image_name = ob.name + " UV Border Bake"
1031        return context.window_manager.invoke_props_dialog(self)
1032
1033    def draw(self, context):
1034        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1035        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1036        row = self.layout.row(align=True)
1037        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1038        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1039        self.layout.label(text="縁設定", icon=compat.icon('CLIPUV_DEHLT'))
1040        self.layout.prop(self, 'blur_type', icon='BRUSH_BLUR')
1041        self.layout.prop(self, 'blur_strength', icon='ARROW_LEFTRIGHT')
1042        row = self.layout.row(align=True)
1043        row.prop(self, 'normalize', icon='IMAGE_ALPHA')
1044        row.prop(self, 'keep_alpha', icon='IMAGE_RGB_ALPHA')
1045
1046    def execute(self, context):
1047        ob = context.active_object
1048        me = ob.data
1049        ob.hide_render = False
1050
1051        override = context.copy()
1052        override['object'] = ob
1053
1054        image_width, image_height = int(self.image_width), int(self.image_height)
1055
1056        if self.image_name in context.blend_data.images:
1057            img = context.blend_data.images[self.image_name]
1058        else:
1059            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1060
1061        area = common.get_request_area(context, 'IMAGE_EDITOR')
1062
1063        img.generated_color = (0, 0, 0, 1)
1064
1065        for elem in me.uv_textures.active.data:
1066            elem.image = img
1067
1068        material_restore = common.material_restore(ob)
1069
1070        bpy.ops.object.material_slot_add(override)
1071        temp_mate = context.blend_data.materials.new("quick_gradation_bake_image_temp")
1072        ob.material_slots[0].material = temp_mate
1073        temp_mate.diffuse_color = (1, 1, 1)
1074
1075        pre_use_bake_clear = context.scene.render.use_bake_clear
1076        pre_bake_margin = context.scene.render.bake_margin
1077        context.scene.render.use_bake_clear = False
1078        context.scene.render.bake_type = 'TEXTURE'
1079        context.scene.render.use_bake_selected_to_active = False
1080
1081        bpy.ops.object.bake_image()
1082        img_w, img_h, img_c = img.size[0], img.size[1], img.channels
1083        pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
1084        img_alphas = pixels[:,:,0]
1085
1086        img.reload()
1087        context.scene.render.bake_margin = 0
1088        bpy.ops.object.bake_image()
1089
1090        context.scene.render.use_bake_clear = pre_use_bake_clear
1091        context.scene.render.bake_margin = pre_bake_margin
1092
1093        # 無駄に壮大なぼかし処理
1094        pre_resolution_x = context.scene.render.resolution_x
1095        pre_resolution_y = context.scene.render.resolution_y
1096        pre_resolution_percentage = context.scene.render.resolution_percentage
1097        context.scene.render.resolution_x = img.size[0]
1098        context.scene.render.resolution_y = img.size[1]
1099        context.scene.render.resolution_percentage = 100
1100
1101        context.scene.use_nodes = True
1102        node_tree = context.scene.node_tree
1103        for node in node_tree.nodes:
1104            node_tree.nodes.remove(node)
1105
1106        img_node = node_tree.nodes.new('CompositorNodeImage')
1107        img_node.location = (0, 0)
1108        img_node.image = img
1109
1110        blur_node = node_tree.nodes.new('CompositorNodeBlur')
1111        blur_node.location = (250, 0)
1112        blur_node.size_x, blur_node.size_y = 1, 1
1113        blur_node.filter_type = self.blur_type
1114        blur_node.inputs[1].default_value = self.blur_strength
1115
1116        out_node = node_tree.nodes.new('CompositorNodeComposite')
1117        out_node.location = (500, 0)
1118
1119        node_tree.links.new(blur_node.inputs[0], img_node.outputs[0])
1120        node_tree.links.new(out_node.inputs[0], blur_node.outputs[0])
1121
1122        bpy.ops.render.render()
1123
1124        render_img = context.blend_data.images["Render Result"]
1125
1126        temp_png_path = os.path.join(bpy.app.tempdir, "temp.png")
1127        img_override = context.copy()
1128        img_override['object'] = render_img
1129        img_override['edit_image'] = render_img
1130        img_override['area'] = area
1131        common.set_area_space_attr(area, 'image', render_img)
1132        bpy.ops.image.save_as(img_override, save_as_render=True, copy=True, filepath=temp_png_path, relative_path=False, show_multiview=False, use_multiview=False)
1133        img.source = 'FILE'
1134        img.filepath = temp_png_path
1135        img.reload()
1136        pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
1137        if self.keep_alpha:
1138            pixels[:,:,3] = img_alphas
1139        if self.normalize:
1140            pixels[:,:,:3] -= 0.5
1141            pixels[:,:,:3] *= 2.0
1142        img.pixels = pixels.flatten()
1143        img.pack(as_png=True)
1144        os.remove(temp_png_path)
1145
1146        for node in node_tree.nodes:
1147            node_tree.nodes.remove(node)
1148        context.scene.use_nodes = False
1149        context.scene.render.resolution_x = pre_resolution_x
1150        context.scene.render.resolution_y = pre_resolution_y
1151        context.scene.render.resolution_percentage = pre_resolution_percentage
1152        # 無駄に壮大なぼかし処理 完
1153
1154        common.set_area_space_attr(area, 'image', img)
1155        common.remove_data([temp_mate])
1156        material_restore.restore()
1157
1158        return {'FINISHED'}
bl_idname = 'object.quick_uv_border_bake_image'
bl_label = 'UV縁・ベイク'
bl_description = 'アクティブオブジェクトに素早くUVの縁を黒くベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('FLAT', 'フラット', '', 'IPO_CONSTANT', 1), ('TENT', 'テント', '', 'IPO_LINEAR', 2), ('QUAD', '二次式', '', 'IPO_QUAD', 3), ('CUBIC', '三次式', '', 'IPO_CUBIC', 4), ('GAUSS', 'ガウシアン', '', 'HAND', 5), ('FAST_GAUSS', '高速ガウシアン', '', 'ALIASED', 6), ('CATROM', 'Catrom', '', 'FILE_TICK', 7), ('MITCH', 'Mitch', '', 'FILE_TICK', 8)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
blur_type: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('FLAT', 'フラット', '', 'IPO_CONSTANT', 1), ('TENT', 'テント', '', 'IPO_LINEAR', 2), ('QUAD', '二次式', '', 'IPO_QUAD', 3), ('CUBIC', '三次式', '', 'IPO_CUBIC', 4), ('GAUSS', 'ガウシアン', '', 'HAND', 5), ('FAST_GAUSS', '高速ガウシアン', '', 'ALIASED', 6), ('CATROM', 'Catrom', '', 'FILE_TICK', 7), ('MITCH', 'Mitch', '', 'FILE_TICK', 8)], 'name': 'ぼかしタイプ', 'default': 'GAUSS', 'attr': 'blur_type'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('FLAT', 'フラット', '', 'IPO_CONSTANT', 1), ('TENT', 'テント', '', 'IPO_LINEAR', 2), ('QUAD', '二次式', '', 'IPO_QUAD', 3), ('CUBIC', '三次式', '', 'IPO_CUBIC', 4), ('GAUSS', 'ガウシアン', '', 'HAND', 5), ('FAST_GAUSS', '高速ガウシアン', '', 'ALIASED', 6), ('CATROM', 'Catrom', '', 'FILE_TICK', 7), ('MITCH', 'Mitch', '', 'FILE_TICK', 8)], 'name': 'ぼかしタイプ', 'default': 'GAUSS', 'attr': 'blur_type'}>
blur_strength: <_PropertyDeferred, <built-in function IntProperty>, {'name': 'ぼかし強度', 'default': 100, 'min': 0, 'max': 1000, 'soft_min': 0, 'soft_max': 1000, 'attr': 'blur_strength'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': 'ぼかし強度', 'default': 100, 'min': 0, 'max': 1000, 'soft_min': 0, 'soft_max': 1000, 'attr': 'blur_strength'}>
normalize: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '正規化', 'default': True, 'attr': 'normalize'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '正規化', 'default': True, 'attr': 'normalize'}>
keep_alpha: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '余白を透過', 'default': True, 'attr': 'keep_alpha'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '余白を透過', 'default': True, 'attr': 'keep_alpha'}>
@classmethod
def poll(cls, context):
1016    @classmethod
1017    def poll(cls, context):
1018        if len(context.selected_objects) != 1:
1019            return False
1020        ob = context.active_object
1021        if ob:
1022            if ob.type == 'MESH':
1023                me = ob.data
1024                if len(me.uv_layers):
1025                    return True
1026        return False
def invoke(self, context, event):
1028    def invoke(self, context, event):
1029        ob = context.active_object
1030        self.image_name = ob.name + " UV Border Bake"
1031        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
1033    def draw(self, context):
1034        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1035        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1036        row = self.layout.row(align=True)
1037        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1038        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1039        self.layout.label(text="縁設定", icon=compat.icon('CLIPUV_DEHLT'))
1040        self.layout.prop(self, 'blur_type', icon='BRUSH_BLUR')
1041        self.layout.prop(self, 'blur_strength', icon='ARROW_LEFTRIGHT')
1042        row = self.layout.row(align=True)
1043        row.prop(self, 'normalize', icon='IMAGE_ALPHA')
1044        row.prop(self, 'keep_alpha', icon='IMAGE_RGB_ALPHA')
def execute(self, context):
1046    def execute(self, context):
1047        ob = context.active_object
1048        me = ob.data
1049        ob.hide_render = False
1050
1051        override = context.copy()
1052        override['object'] = ob
1053
1054        image_width, image_height = int(self.image_width), int(self.image_height)
1055
1056        if self.image_name in context.blend_data.images:
1057            img = context.blend_data.images[self.image_name]
1058        else:
1059            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1060
1061        area = common.get_request_area(context, 'IMAGE_EDITOR')
1062
1063        img.generated_color = (0, 0, 0, 1)
1064
1065        for elem in me.uv_textures.active.data:
1066            elem.image = img
1067
1068        material_restore = common.material_restore(ob)
1069
1070        bpy.ops.object.material_slot_add(override)
1071        temp_mate = context.blend_data.materials.new("quick_gradation_bake_image_temp")
1072        ob.material_slots[0].material = temp_mate
1073        temp_mate.diffuse_color = (1, 1, 1)
1074
1075        pre_use_bake_clear = context.scene.render.use_bake_clear
1076        pre_bake_margin = context.scene.render.bake_margin
1077        context.scene.render.use_bake_clear = False
1078        context.scene.render.bake_type = 'TEXTURE'
1079        context.scene.render.use_bake_selected_to_active = False
1080
1081        bpy.ops.object.bake_image()
1082        img_w, img_h, img_c = img.size[0], img.size[1], img.channels
1083        pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
1084        img_alphas = pixels[:,:,0]
1085
1086        img.reload()
1087        context.scene.render.bake_margin = 0
1088        bpy.ops.object.bake_image()
1089
1090        context.scene.render.use_bake_clear = pre_use_bake_clear
1091        context.scene.render.bake_margin = pre_bake_margin
1092
1093        # 無駄に壮大なぼかし処理
1094        pre_resolution_x = context.scene.render.resolution_x
1095        pre_resolution_y = context.scene.render.resolution_y
1096        pre_resolution_percentage = context.scene.render.resolution_percentage
1097        context.scene.render.resolution_x = img.size[0]
1098        context.scene.render.resolution_y = img.size[1]
1099        context.scene.render.resolution_percentage = 100
1100
1101        context.scene.use_nodes = True
1102        node_tree = context.scene.node_tree
1103        for node in node_tree.nodes:
1104            node_tree.nodes.remove(node)
1105
1106        img_node = node_tree.nodes.new('CompositorNodeImage')
1107        img_node.location = (0, 0)
1108        img_node.image = img
1109
1110        blur_node = node_tree.nodes.new('CompositorNodeBlur')
1111        blur_node.location = (250, 0)
1112        blur_node.size_x, blur_node.size_y = 1, 1
1113        blur_node.filter_type = self.blur_type
1114        blur_node.inputs[1].default_value = self.blur_strength
1115
1116        out_node = node_tree.nodes.new('CompositorNodeComposite')
1117        out_node.location = (500, 0)
1118
1119        node_tree.links.new(blur_node.inputs[0], img_node.outputs[0])
1120        node_tree.links.new(out_node.inputs[0], blur_node.outputs[0])
1121
1122        bpy.ops.render.render()
1123
1124        render_img = context.blend_data.images["Render Result"]
1125
1126        temp_png_path = os.path.join(bpy.app.tempdir, "temp.png")
1127        img_override = context.copy()
1128        img_override['object'] = render_img
1129        img_override['edit_image'] = render_img
1130        img_override['area'] = area
1131        common.set_area_space_attr(area, 'image', render_img)
1132        bpy.ops.image.save_as(img_override, save_as_render=True, copy=True, filepath=temp_png_path, relative_path=False, show_multiview=False, use_multiview=False)
1133        img.source = 'FILE'
1134        img.filepath = temp_png_path
1135        img.reload()
1136        pixels = numpy.array(img.pixels).reshape(img_h, img_w, img_c)
1137        if self.keep_alpha:
1138            pixels[:,:,3] = img_alphas
1139        if self.normalize:
1140            pixels[:,:,:3] -= 0.5
1141            pixels[:,:,:3] *= 2.0
1142        img.pixels = pixels.flatten()
1143        img.pack(as_png=True)
1144        os.remove(temp_png_path)
1145
1146        for node in node_tree.nodes:
1147            node_tree.nodes.remove(node)
1148        context.scene.use_nodes = False
1149        context.scene.render.resolution_x = pre_resolution_x
1150        context.scene.render.resolution_y = pre_resolution_y
1151        context.scene.render.resolution_percentage = pre_resolution_percentage
1152        # 無駄に壮大なぼかし処理 完
1153
1154        common.set_area_space_attr(area, 'image', img)
1155        common.remove_data([temp_mate])
1156        material_restore.restore()
1157
1158        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_uv_border_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_mesh_border_bake_image(bpy_types.Operator):
1161@compat.BlRegister()
1162class CNV_OT_quick_mesh_border_bake_image(bpy.types.Operator):
1163    bl_idname = 'object.quick_mesh_border_bake_image'
1164    bl_label = "メッシュ縁・ベイク"
1165    bl_description = "アクティブオブジェクトに素早くメッシュの縁を黒くベイクします"
1166    bl_options = {'REGISTER', 'UNDO'}
1167
1168    image_name = bpy.props.StringProperty(name="画像名")
1169    items = [
1170        ('128', "128 px", "", 'LAYER_USED', 1),
1171        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1172        ('512', "512 px", "", 'HAND', 3),
1173        ('1024', "1024 px", "", 'FILE_TICK', 4),
1174        ('2048', "2048 px", "", 'ERROR', 5),
1175        ('4096', "4096 px", "", 'CANCEL', 6),
1176        ]
1177    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1178    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1179
1180    range = bpy.props.IntProperty(name="範囲", default=5, min=1, max=50, soft_min=1, soft_max=50)
1181
1182    @classmethod
1183    def poll(cls, context):
1184        if len(context.selected_objects) != 1:
1185            return False
1186        ob = context.active_object
1187        if ob:
1188            if ob.type == 'MESH':
1189                me = ob.data
1190                if len(me.uv_layers):
1191                    return True
1192        return False
1193
1194    def invoke(self, context, event):
1195        ob = context.active_object
1196        self.image_name = ob.name + " Mesh Border Bake"
1197        return context.window_manager.invoke_props_dialog(self)
1198
1199    def draw(self, context):
1200        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1201        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1202        row = self.layout.row(align=True)
1203        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1204        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1205
1206        self.layout.prop(self, 'range', icon='PROP_ON')
1207
1208    def execute(self, context):
1209        ob = context.active_object
1210        me = ob.data
1211        compat.set_select(ob, False)
1212        ob.hide_render = False
1213
1214        image_width, image_height = int(self.image_width), int(self.image_height)
1215
1216        if self.image_name in context.blend_data.images:
1217            img = context.blend_data.images[self.image_name]
1218        else:
1219            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1220
1221        area = common.get_request_area(context, 'IMAGE_EDITOR')
1222        common.set_area_space_attr(area, 'image', img)
1223        for elem in me.uv_textures.active.data:
1224            elem.image = img
1225
1226        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1227        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1228        compat.link(context.scene, temp_ob)
1229        for vc in temp_me.vertex_colors:
1230            temp_me.vertex_colors.remove(vc)
1231        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1232        compat.set_active(context, temp_ob)
1233        compat.set_select(temp_ob, True)
1234
1235        def paint_selected_vertices(me, color, except_indices=[]):
1236            paint_vertices = []
1237            for vert in me.vertices:
1238                if vert.select and vert.index not in except_indices:
1239                    paint_vertices.append(vert.index)
1240            for loop in me.loops:
1241                if loop.vertex_index in paint_vertices:
1242                    me.vertex_colors.active.data[loop.index].color = color
1243            return paint_vertices
1244
1245        context.tool_settings.mesh_select_mode = (True, False, False)
1246        already_vert_indices = []
1247        for index in range(self.range):
1248            bpy.ops.object.mode_set(mode='EDIT')
1249            if index == 0:
1250                bpy.ops.mesh.reveal()
1251                bpy.ops.mesh.select_all(action='DESELECT')
1252                bpy.ops.mesh.select_non_manifold()
1253            else:
1254                bpy.ops.mesh.select_more()
1255            bpy.ops.object.mode_set(mode='OBJECT')
1256
1257            value = (1.0 / self.range) * index
1258            already_vert_indices += paint_selected_vertices(temp_me, [value, value, value], already_vert_indices)
1259
1260        bpy.ops.object.mode_set(mode='EDIT')
1261        bpy.ops.mesh.select_all(action='DESELECT')
1262        bpy.ops.object.mode_set(mode='OBJECT')
1263
1264        context.scene.render.bake_type = 'VERTEX_COLORS'
1265        context.scene.render.use_bake_selected_to_active = False
1266        bpy.ops.object.bake_image()
1267
1268        common.remove_data([temp_me, temp_ob])
1269        compat.set_active(context, ob)
1270        compat.set_select(ob, True)
1271
1272        return {'FINISHED'}
bl_idname = 'object.quick_mesh_border_bake_image'
bl_label = 'メッシュ縁・ベイク'
bl_description = 'アクティブオブジェクトに素早くメッシュの縁を黒くベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
range: <_PropertyDeferred, <built-in function IntProperty>, {'name': '範囲', 'default': 5, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'range'}> = <_PropertyDeferred, <built-in function IntProperty>, {'name': '範囲', 'default': 5, 'min': 1, 'max': 50, 'soft_min': 1, 'soft_max': 50, 'attr': 'range'}>
@classmethod
def poll(cls, context):
1182    @classmethod
1183    def poll(cls, context):
1184        if len(context.selected_objects) != 1:
1185            return False
1186        ob = context.active_object
1187        if ob:
1188            if ob.type == 'MESH':
1189                me = ob.data
1190                if len(me.uv_layers):
1191                    return True
1192        return False
def invoke(self, context, event):
1194    def invoke(self, context, event):
1195        ob = context.active_object
1196        self.image_name = ob.name + " Mesh Border Bake"
1197        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
1199    def draw(self, context):
1200        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1201        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1202        row = self.layout.row(align=True)
1203        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1204        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1205
1206        self.layout.prop(self, 'range', icon='PROP_ON')
def execute(self, context):
1208    def execute(self, context):
1209        ob = context.active_object
1210        me = ob.data
1211        compat.set_select(ob, False)
1212        ob.hide_render = False
1213
1214        image_width, image_height = int(self.image_width), int(self.image_height)
1215
1216        if self.image_name in context.blend_data.images:
1217            img = context.blend_data.images[self.image_name]
1218        else:
1219            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1220
1221        area = common.get_request_area(context, 'IMAGE_EDITOR')
1222        common.set_area_space_attr(area, 'image', img)
1223        for elem in me.uv_textures.active.data:
1224            elem.image = img
1225
1226        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1227        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1228        compat.link(context.scene, temp_ob)
1229        for vc in temp_me.vertex_colors:
1230            temp_me.vertex_colors.remove(vc)
1231        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1232        compat.set_active(context, temp_ob)
1233        compat.set_select(temp_ob, True)
1234
1235        def paint_selected_vertices(me, color, except_indices=[]):
1236            paint_vertices = []
1237            for vert in me.vertices:
1238                if vert.select and vert.index not in except_indices:
1239                    paint_vertices.append(vert.index)
1240            for loop in me.loops:
1241                if loop.vertex_index in paint_vertices:
1242                    me.vertex_colors.active.data[loop.index].color = color
1243            return paint_vertices
1244
1245        context.tool_settings.mesh_select_mode = (True, False, False)
1246        already_vert_indices = []
1247        for index in range(self.range):
1248            bpy.ops.object.mode_set(mode='EDIT')
1249            if index == 0:
1250                bpy.ops.mesh.reveal()
1251                bpy.ops.mesh.select_all(action='DESELECT')
1252                bpy.ops.mesh.select_non_manifold()
1253            else:
1254                bpy.ops.mesh.select_more()
1255            bpy.ops.object.mode_set(mode='OBJECT')
1256
1257            value = (1.0 / self.range) * index
1258            already_vert_indices += paint_selected_vertices(temp_me, [value, value, value], already_vert_indices)
1259
1260        bpy.ops.object.mode_set(mode='EDIT')
1261        bpy.ops.mesh.select_all(action='DESELECT')
1262        bpy.ops.object.mode_set(mode='OBJECT')
1263
1264        context.scene.render.bake_type = 'VERTEX_COLORS'
1265        context.scene.render.use_bake_selected_to_active = False
1266        bpy.ops.object.bake_image()
1267
1268        common.remove_data([temp_me, temp_ob])
1269        compat.set_active(context, ob)
1270        compat.set_select(ob, True)
1271
1272        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_mesh_border_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_density_bake_image(bpy_types.Operator):
1275@compat.BlRegister()
1276class CNV_OT_quick_density_bake_image(bpy.types.Operator):
1277    bl_idname = 'object.quick_density_bake_image'
1278    bl_label = "密度・ベイク"
1279    bl_description = "アクティブオブジェクトに素早く密度をベイクします"
1280    bl_options = {'REGISTER', 'UNDO'}
1281
1282    image_name = bpy.props.StringProperty(name="画像名")
1283    items = [
1284        ('128', "128 px", "", 'LAYER_USED', 1),
1285        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1286        ('512', "512 px", "", 'HAND', 3),
1287        ('1024', "1024 px", "", 'FILE_TICK', 4),
1288        ('2048', "2048 px", "", 'ERROR', 5),
1289        ('4096', "4096 px", "", 'CANCEL', 6),
1290        ]
1291    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1292    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1293
1294    items = [
1295        ('ALL', "全て", "", 'MOD_SUBSURF', 1),
1296        ('PARTS', "パーツごと", "", 'GROUP_VCOL', 2),
1297        ]
1298    mode = bpy.props.EnumProperty(items=items, name="比較対象", default='PARTS')
1299
1300    @classmethod
1301    def poll(cls, context):
1302        if len(context.selected_objects) != 1:
1303            return False
1304        ob = context.active_object
1305        if ob:
1306            if ob.type == 'MESH':
1307                me = ob.data
1308                if len(me.uv_layers):
1309                    return True
1310        return False
1311
1312    def invoke(self, context, event):
1313        ob = context.active_object
1314        self.image_name = ob.name + " Density Bake"
1315        return context.window_manager.invoke_props_dialog(self)
1316
1317    def draw(self, context):
1318        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1319        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1320        row = self.layout.row(align=True)
1321        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1322        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1323        self.layout.label(text="比較対象", icon='ZOOM_PREVIOUS')
1324        self.layout.prop(self, 'mode', icon='ZOOM_PREVIOUS', expand=True)
1325
1326    def execute(self, context):
1327        ob = context.active_object
1328        me = ob.data
1329        compat.set_select(ob, False)
1330        ob.hide_render = False
1331
1332        image_width, image_height = int(self.image_width), int(self.image_height)
1333
1334        if self.image_name in context.blend_data.images:
1335            img = context.blend_data.images[self.image_name]
1336        else:
1337            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1338
1339        area = common.get_request_area(context, 'IMAGE_EDITOR')
1340        common.set_area_space_attr(area, 'image', img)
1341        for elem in me.uv_textures.active.data:
1342            elem.image = img
1343
1344        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1345        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1346        compat.link(context.scene, temp_ob)
1347        for vc in temp_me.vertex_colors:
1348            temp_me.vertex_colors.remove(vc)
1349        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1350        compat.set_active(context, temp_ob)
1351        compat.set_select(temp_ob, True)
1352
1353        bm = bmesh.new()
1354        bm.from_mesh(temp_me)
1355        bm.verts.ensure_lookup_table()
1356
1357        vert_islands = []
1358        if self.mode == 'ALL':
1359            vert_islands.append([v.index for v in bm.verts])
1360        elif self.mode == 'PARTS':
1361            alread_vert_indices = []
1362            for i in range(9**9):
1363
1364                vert_islands.append([])
1365
1366                for vert in bm.verts:
1367                    if vert.index not in alread_vert_indices:
1368                        new_verts = [vert]
1369                        alread_vert_indices.append(vert.index)
1370                        vert_islands[-1].append(vert.index)
1371                        break
1372
1373                for j in range(9**9):
1374
1375                    vs = []
1376                    for vert in new_verts:
1377                        for edge in vert.link_edges:
1378                            for v in edge.verts:
1379                                if vert.index != v.index and v.index not in alread_vert_indices:
1380                                    vs.append(v)
1381                                    alread_vert_indices.append(v.index)
1382                                    vert_islands[-1].append(v.index)
1383                                    break
1384
1385                    if not len(vs):
1386                        break
1387
1388                    new_verts = vs[:]
1389
1390                if len(bm.verts) <= len(alread_vert_indices):
1391                    break
1392
1393        for island in vert_islands:
1394            edge_lens = []
1395            for index in island:
1396                lens = [e.calc_length() for e in bm.verts[index].link_edges]
1397                edge_lens.append( sum(lens) / len(lens) )
1398            edge_min, edge_max = min(edge_lens), max(edge_lens)
1399            try:
1400                multi = 1.0 / (edge_max - edge_min)
1401            except:
1402                multi = 1.0
1403
1404            for index in island:
1405                vert = bm.verts[index]
1406
1407                lens = [e.calc_length() for e in vert.link_edges]
1408                l = sum(lens) / len(lens)
1409                value = (l - edge_min) * multi
1410                for loop in vert.link_loops:
1411                    temp_vertex_color.data[loop.index].color = (value, value, value)
1412
1413        context.scene.render.bake_type = 'VERTEX_COLORS'
1414        context.scene.render.use_bake_selected_to_active = False
1415        bpy.ops.object.bake_image()
1416
1417        common.remove_data([temp_me, temp_ob])
1418        compat.set_active(context, ob)
1419        compat.set_select(ob, True)
1420
1421        return {'FINISHED'}
bl_idname = 'object.quick_density_bake_image'
bl_label = '密度・ベイク'
bl_description = 'アクティブオブジェクトに素早く密度をベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('ALL', '全て', '', 'MOD_SUBSURF', 1), ('PARTS', 'パーツごと', '', 'GROUP_VCOL', 2)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
mode: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('ALL', '全て', '', 'MOD_SUBSURF', 1), ('PARTS', 'パーツごと', '', 'GROUP_VCOL', 2)], 'name': '比較対象', 'default': 'PARTS', 'attr': 'mode'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('ALL', '全て', '', 'MOD_SUBSURF', 1), ('PARTS', 'パーツごと', '', 'GROUP_VCOL', 2)], 'name': '比較対象', 'default': 'PARTS', 'attr': 'mode'}>
@classmethod
def poll(cls, context):
1300    @classmethod
1301    def poll(cls, context):
1302        if len(context.selected_objects) != 1:
1303            return False
1304        ob = context.active_object
1305        if ob:
1306            if ob.type == 'MESH':
1307                me = ob.data
1308                if len(me.uv_layers):
1309                    return True
1310        return False
def invoke(self, context, event):
1312    def invoke(self, context, event):
1313        ob = context.active_object
1314        self.image_name = ob.name + " Density Bake"
1315        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
1317    def draw(self, context):
1318        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1319        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1320        row = self.layout.row(align=True)
1321        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1322        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1323        self.layout.label(text="比較対象", icon='ZOOM_PREVIOUS')
1324        self.layout.prop(self, 'mode', icon='ZOOM_PREVIOUS', expand=True)
def execute(self, context):
1326    def execute(self, context):
1327        ob = context.active_object
1328        me = ob.data
1329        compat.set_select(ob, False)
1330        ob.hide_render = False
1331
1332        image_width, image_height = int(self.image_width), int(self.image_height)
1333
1334        if self.image_name in context.blend_data.images:
1335            img = context.blend_data.images[self.image_name]
1336        else:
1337            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1338
1339        area = common.get_request_area(context, 'IMAGE_EDITOR')
1340        common.set_area_space_attr(area, 'image', img)
1341        for elem in me.uv_textures.active.data:
1342            elem.image = img
1343
1344        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1345        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1346        compat.link(context.scene, temp_ob)
1347        for vc in temp_me.vertex_colors:
1348            temp_me.vertex_colors.remove(vc)
1349        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1350        compat.set_active(context, temp_ob)
1351        compat.set_select(temp_ob, True)
1352
1353        bm = bmesh.new()
1354        bm.from_mesh(temp_me)
1355        bm.verts.ensure_lookup_table()
1356
1357        vert_islands = []
1358        if self.mode == 'ALL':
1359            vert_islands.append([v.index for v in bm.verts])
1360        elif self.mode == 'PARTS':
1361            alread_vert_indices = []
1362            for i in range(9**9):
1363
1364                vert_islands.append([])
1365
1366                for vert in bm.verts:
1367                    if vert.index not in alread_vert_indices:
1368                        new_verts = [vert]
1369                        alread_vert_indices.append(vert.index)
1370                        vert_islands[-1].append(vert.index)
1371                        break
1372
1373                for j in range(9**9):
1374
1375                    vs = []
1376                    for vert in new_verts:
1377                        for edge in vert.link_edges:
1378                            for v in edge.verts:
1379                                if vert.index != v.index and v.index not in alread_vert_indices:
1380                                    vs.append(v)
1381                                    alread_vert_indices.append(v.index)
1382                                    vert_islands[-1].append(v.index)
1383                                    break
1384
1385                    if not len(vs):
1386                        break
1387
1388                    new_verts = vs[:]
1389
1390                if len(bm.verts) <= len(alread_vert_indices):
1391                    break
1392
1393        for island in vert_islands:
1394            edge_lens = []
1395            for index in island:
1396                lens = [e.calc_length() for e in bm.verts[index].link_edges]
1397                edge_lens.append( sum(lens) / len(lens) )
1398            edge_min, edge_max = min(edge_lens), max(edge_lens)
1399            try:
1400                multi = 1.0 / (edge_max - edge_min)
1401            except:
1402                multi = 1.0
1403
1404            for index in island:
1405                vert = bm.verts[index]
1406
1407                lens = [e.calc_length() for e in vert.link_edges]
1408                l = sum(lens) / len(lens)
1409                value = (l - edge_min) * multi
1410                for loop in vert.link_loops:
1411                    temp_vertex_color.data[loop.index].color = (value, value, value)
1412
1413        context.scene.render.bake_type = 'VERTEX_COLORS'
1414        context.scene.render.use_bake_selected_to_active = False
1415        bpy.ops.object.bake_image()
1416
1417        common.remove_data([temp_me, temp_ob])
1418        compat.set_active(context, ob)
1419        compat.set_select(ob, True)
1420
1421        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_density_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_mesh_distance_bake_image(bpy_types.Operator):
1424@compat.BlRegister()
1425class CNV_OT_quick_mesh_distance_bake_image(bpy.types.Operator):
1426    bl_idname = 'object.quick_mesh_distance_bake_image'
1427    bl_label = "メッシュ間距離・ベイク"
1428    bl_description = "アクティブオブジェクトに他オブジェクトとの距離をベイクします"
1429    bl_options = {'REGISTER', 'UNDO'}
1430
1431    image_name = bpy.props.StringProperty(name="画像名")
1432    items = [
1433        ('128', "128 px", "", 'LAYER_USED', 1),
1434        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1435        ('512', "512 px", "", 'HAND', 3),
1436        ('1024', "1024 px", "", 'FILE_TICK', 4),
1437        ('2048', "2048 px", "", 'ERROR', 5),
1438        ('4096', "4096 px", "", 'CANCEL', 6),
1439        ]
1440    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1441    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1442
1443    @classmethod
1444    def poll(cls, context):
1445        obs = context.selected_objects
1446        if len(obs) != 2: return False
1447        for ob in obs:
1448            if ob.type != 'MESH':
1449                return False
1450        me = context.active_object.data
1451        if len(me.uv_layers):
1452            return True
1453        return False
1454
1455    def invoke(self, context, event):
1456        ob = context.active_object
1457        self.image_name = ob.name + " Mesh Distance Bake"
1458        return context.window_manager.invoke_props_dialog(self)
1459
1460    def draw(self, context):
1461        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1462        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1463        row = self.layout.row(align=True)
1464        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1465        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1466
1467    def execute(self, context):
1468        target_ob = context.active_object
1469        target_ob.hide_render = False
1470        for ob in context.selected_objects:
1471            if ob.name != target_ob.name:
1472                source_ob = ob
1473            compat.set_select(ob, False)
1474        target_me = target_ob.data
1475        source_me = source_ob.data
1476
1477        image_width, image_height = int(self.image_width), int(self.image_height)
1478
1479        if self.image_name in context.blend_data.images:
1480            img = context.blend_data.images[self.image_name]
1481        else:
1482            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1483
1484        area = common.get_request_area(context, 'IMAGE_EDITOR')
1485        common.set_area_space_attr(area, 'image', img)
1486        for elem in target_me.uv_textures.active.data:
1487            elem.image = img
1488
1489        temp_me = target_ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1490        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1491        compat.link(context.scene, temp_ob)
1492        for vc in temp_me.vertex_colors:
1493            temp_me.vertex_colors.remove(vc)
1494        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1495        compat.set_active(context, temp_ob)
1496        compat.set_select(temp_ob, True)
1497
1498        bvh = mathutils.bvhtree.BVHTree.FromObject(source_ob, context.scene)
1499
1500        vert_dists = []
1501        for vert in temp_me.vertices:
1502            co = compat.mul(target_ob.matrix_world, vert.co)
1503            location, normal, index, dist = bvh.find(co)
1504            vert_dists.append(dist)
1505
1506        dist_min, dist_max = min(vert_dists), max(vert_dists)
1507        try:
1508            multi = 1.0 / (dist_max - dist_min)
1509        except:
1510            multi = 1.0
1511
1512        for loop in temp_me.loops:
1513            value = ( vert_dists[loop.vertex_index] - dist_min ) * multi
1514            temp_vertex_color.data[loop.index].color = (value, value, value)
1515
1516        context.scene.render.bake_type = 'VERTEX_COLORS'
1517        context.scene.render.use_bake_selected_to_active = False
1518        bpy.ops.object.bake_image()
1519
1520        common.remove_data([temp_me, temp_ob])
1521        compat.set_active(context, target_ob)
1522        compat.set_select(target_ob, True)
1523        compat.set_select(source_ob, True)
1524
1525        return {'FINISHED'}
bl_idname = 'object.quick_mesh_distance_bake_image'
bl_label = 'メッシュ間距離・ベイク'
bl_description = 'アクティブオブジェクトに他オブジェクトとの距離をベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
@classmethod
def poll(cls, context):
1443    @classmethod
1444    def poll(cls, context):
1445        obs = context.selected_objects
1446        if len(obs) != 2: return False
1447        for ob in obs:
1448            if ob.type != 'MESH':
1449                return False
1450        me = context.active_object.data
1451        if len(me.uv_layers):
1452            return True
1453        return False
def invoke(self, context, event):
1455    def invoke(self, context, event):
1456        ob = context.active_object
1457        self.image_name = ob.name + " Mesh Distance Bake"
1458        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
1460    def draw(self, context):
1461        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1462        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1463        row = self.layout.row(align=True)
1464        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1465        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
def execute(self, context):
1467    def execute(self, context):
1468        target_ob = context.active_object
1469        target_ob.hide_render = False
1470        for ob in context.selected_objects:
1471            if ob.name != target_ob.name:
1472                source_ob = ob
1473            compat.set_select(ob, False)
1474        target_me = target_ob.data
1475        source_me = source_ob.data
1476
1477        image_width, image_height = int(self.image_width), int(self.image_height)
1478
1479        if self.image_name in context.blend_data.images:
1480            img = context.blend_data.images[self.image_name]
1481        else:
1482            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1483
1484        area = common.get_request_area(context, 'IMAGE_EDITOR')
1485        common.set_area_space_attr(area, 'image', img)
1486        for elem in target_me.uv_textures.active.data:
1487            elem.image = img
1488
1489        temp_me = target_ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1490        temp_ob = context.blend_data.objects.new("quick_density_bake_image", temp_me)
1491        compat.link(context.scene, temp_ob)
1492        for vc in temp_me.vertex_colors:
1493            temp_me.vertex_colors.remove(vc)
1494        temp_vertex_color = temp_me.vertex_colors.new(name="quick_density_bake_image")
1495        compat.set_active(context, temp_ob)
1496        compat.set_select(temp_ob, True)
1497
1498        bvh = mathutils.bvhtree.BVHTree.FromObject(source_ob, context.scene)
1499
1500        vert_dists = []
1501        for vert in temp_me.vertices:
1502            co = compat.mul(target_ob.matrix_world, vert.co)
1503            location, normal, index, dist = bvh.find(co)
1504            vert_dists.append(dist)
1505
1506        dist_min, dist_max = min(vert_dists), max(vert_dists)
1507        try:
1508            multi = 1.0 / (dist_max - dist_min)
1509        except:
1510            multi = 1.0
1511
1512        for loop in temp_me.loops:
1513            value = ( vert_dists[loop.vertex_index] - dist_min ) * multi
1514            temp_vertex_color.data[loop.index].color = (value, value, value)
1515
1516        context.scene.render.bake_type = 'VERTEX_COLORS'
1517        context.scene.render.use_bake_selected_to_active = False
1518        bpy.ops.object.bake_image()
1519
1520        common.remove_data([temp_me, temp_ob])
1521        compat.set_active(context, target_ob)
1522        compat.set_select(target_ob, True)
1523        compat.set_select(source_ob, True)
1524
1525        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_mesh_distance_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_bulge_bake_image(bpy_types.Operator):
1528@compat.BlRegister()
1529class CNV_OT_quick_bulge_bake_image(bpy.types.Operator):
1530    bl_idname = 'object.quick_bulge_bake_image'
1531    bl_label = "膨らみ・ベイク"
1532    bl_description = "アクティブオブジェクトに膨らんでいる部分を白くベイクします"
1533    bl_options = {'REGISTER', 'UNDO'}
1534
1535    image_name = bpy.props.StringProperty(name="画像名")
1536    items = [
1537        ('128', "128 px", "", 'LAYER_USED', 1),
1538        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1539        ('512', "512 px", "", 'HAND', 3),
1540        ('1024', "1024 px", "", 'FILE_TICK', 4),
1541        ('2048', "2048 px", "", 'ERROR', 5),
1542        ('4096', "4096 px", "", 'CANCEL', 6),
1543        ]
1544    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1545    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1546
1547    @classmethod
1548    def poll(cls, context):
1549        if len(context.selected_objects) != 1:
1550            return False
1551        ob = context.active_object
1552        if ob:
1553            if ob.type == 'MESH':
1554                me = ob.data
1555                if len(me.uv_layers):
1556                    return True
1557        return False
1558
1559    def invoke(self, context, event):
1560        ob = context.active_object
1561        self.image_name = ob.name + " Bulge Bake"
1562        return context.window_manager.invoke_props_dialog(self)
1563
1564    def draw(self, context):
1565        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1566        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1567        row = self.layout.row(align=True)
1568        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1569        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1570
1571    def execute(self, context):
1572        ob = context.active_object
1573        me = ob.data
1574        compat.set_select(ob, False)
1575        ob.hide_render = False
1576
1577        image_width, image_height = int(self.image_width), int(self.image_height)
1578
1579        if self.image_name in context.blend_data.images:
1580            img = context.blend_data.images[self.image_name]
1581        else:
1582            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1583
1584        area = common.get_request_area(context, 'IMAGE_EDITOR')
1585        common.set_area_space_attr(area, 'image', img)
1586        for elem in me.uv_textures.active.data:
1587            elem.image = img
1588
1589        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1590        temp_ob = context.blend_data.objects.new("quick_bulge_bake_image", temp_me)
1591        compat.link(context.scene, temp_ob)
1592        for vc in temp_me.vertex_colors:
1593            temp_me.vertex_colors.remove(vc)
1594        temp_vertex_color = temp_me.vertex_colors.new(name="quick_bulge_bake_image")
1595        compat.set_active(context, temp_ob)
1596        compat.set_select(temp_ob, True)
1597
1598        bm = bmesh.new()
1599        bm.from_mesh(temp_me)
1600
1601        angles = []
1602        for vert in bm.verts:
1603            normal = vert.normal
1604            edge_angle_total = 0.0
1605            for edge in vert.link_edges:
1606                diff_co = edge.other_vert(vert).co - vert.co
1607                if 0 < diff_co.length:
1608                    edge_angle_total += normal.angle(diff_co)
1609            if len(vert.link_edges):
1610                edge_angle = edge_angle_total / len(vert.link_edges)
1611            else:
1612                edge_angle = 0.0
1613            angles.append(edge_angle)
1614
1615        angle_min, angle_max = 1.5708, max(angles)
1616        multi = 1.0 / (angle_max - angle_min)
1617
1618        for vert in bm.verts:
1619            value = (angles[vert.index] - angle_min) * multi
1620            for loop in vert.link_loops:
1621                temp_vertex_color.data[loop.index].color = (value, value, value)
1622
1623        context.scene.render.bake_type = 'VERTEX_COLORS'
1624        context.scene.render.use_bake_selected_to_active = False
1625        bpy.ops.object.bake_image()
1626
1627        common.remove_data([temp_me, temp_ob])
1628        compat.set_active(context, ob)
1629        compat.set_select(ob, True)
1630
1631        return {'FINISHED'}
bl_idname = 'object.quick_bulge_bake_image'
bl_label = '膨らみ・ベイク'
bl_description = 'アクティブオブジェクトに膨らんでいる部分を白くベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
@classmethod
def poll(cls, context):
1547    @classmethod
1548    def poll(cls, context):
1549        if len(context.selected_objects) != 1:
1550            return False
1551        ob = context.active_object
1552        if ob:
1553            if ob.type == 'MESH':
1554                me = ob.data
1555                if len(me.uv_layers):
1556                    return True
1557        return False
def invoke(self, context, event):
1559    def invoke(self, context, event):
1560        ob = context.active_object
1561        self.image_name = ob.name + " Bulge Bake"
1562        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
1564    def draw(self, context):
1565        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1566        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1567        row = self.layout.row(align=True)
1568        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1569        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
def execute(self, context):
1571    def execute(self, context):
1572        ob = context.active_object
1573        me = ob.data
1574        compat.set_select(ob, False)
1575        ob.hide_render = False
1576
1577        image_width, image_height = int(self.image_width), int(self.image_height)
1578
1579        if self.image_name in context.blend_data.images:
1580            img = context.blend_data.images[self.image_name]
1581        else:
1582            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1583
1584        area = common.get_request_area(context, 'IMAGE_EDITOR')
1585        common.set_area_space_attr(area, 'image', img)
1586        for elem in me.uv_textures.active.data:
1587            elem.image = img
1588
1589        temp_me = ob.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
1590        temp_ob = context.blend_data.objects.new("quick_bulge_bake_image", temp_me)
1591        compat.link(context.scene, temp_ob)
1592        for vc in temp_me.vertex_colors:
1593            temp_me.vertex_colors.remove(vc)
1594        temp_vertex_color = temp_me.vertex_colors.new(name="quick_bulge_bake_image")
1595        compat.set_active(context, temp_ob)
1596        compat.set_select(temp_ob, True)
1597
1598        bm = bmesh.new()
1599        bm.from_mesh(temp_me)
1600
1601        angles = []
1602        for vert in bm.verts:
1603            normal = vert.normal
1604            edge_angle_total = 0.0
1605            for edge in vert.link_edges:
1606                diff_co = edge.other_vert(vert).co - vert.co
1607                if 0 < diff_co.length:
1608                    edge_angle_total += normal.angle(diff_co)
1609            if len(vert.link_edges):
1610                edge_angle = edge_angle_total / len(vert.link_edges)
1611            else:
1612                edge_angle = 0.0
1613            angles.append(edge_angle)
1614
1615        angle_min, angle_max = 1.5708, max(angles)
1616        multi = 1.0 / (angle_max - angle_min)
1617
1618        for vert in bm.verts:
1619            value = (angles[vert.index] - angle_min) * multi
1620            for loop in vert.link_loops:
1621                temp_vertex_color.data[loop.index].color = (value, value, value)
1622
1623        context.scene.render.bake_type = 'VERTEX_COLORS'
1624        context.scene.render.use_bake_selected_to_active = False
1625        bpy.ops.object.bake_image()
1626
1627        common.remove_data([temp_me, temp_ob])
1628        compat.set_active(context, ob)
1629        compat.set_select(ob, True)
1630
1631        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_bulge_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_quick_semen_bake_image(bpy_types.Operator):
1634@compat.BlRegister()
1635class CNV_OT_quick_semen_bake_image(bpy.types.Operator):
1636    bl_idname = 'object.quick_semen_bake_image'
1637    bl_label = "白い液体・ベイク"
1638    bl_description = "アクティブオブジェクトに白い液体をベイクします"
1639    bl_options = {'REGISTER', 'UNDO'}
1640
1641    image_name = bpy.props.StringProperty(name="画像名")
1642    items = [
1643        ('128', "128 px", "", 'LAYER_USED', 1),
1644        ('256', "256 px", "", 'LAYER_ACTIVE', 2),
1645        ('512', "512 px", "", 'HAND', 3),
1646        ('1024', "1024 px", "", 'FILE_TICK', 4),
1647        ('2048', "2048 px", "", 'ERROR', 5),
1648        ('4096', "4096 px", "", 'CANCEL', 6),
1649        ]
1650    image_width = bpy.props.EnumProperty(items=items, name="幅", default='1024')
1651    image_height = bpy.props.EnumProperty(items=items, name="高", default='1024')
1652
1653    texture_scale = bpy.props.FloatProperty(name="テクスチャサイズ", default=1, min=0, max=100, soft_min=0, soft_max=100, step=50, precision=1)
1654
1655    @classmethod
1656    def poll(cls, context):
1657        if len(context.selected_objects) != 1:
1658            return False
1659        ob = context.active_object
1660        if ob:
1661            if ob.type == 'MESH':
1662                me = ob.data
1663                if len(me.uv_layers):
1664                    return True
1665        return False
1666
1667    def invoke(self, context, event):
1668        ob = context.active_object
1669        self.image_name = ob.name + " Semen Bake"
1670        return context.window_manager.invoke_props_dialog(self)
1671
1672    def draw(self, context):
1673        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1674        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1675        row = self.layout.row(align=True)
1676        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1677        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1678
1679        self.layout.prop(self, 'texture_scale', icon='TEXTURE')
1680
1681    def execute(self, context):
1682        ob = context.active_object
1683        me = ob.data
1684        ob.hide_render = False
1685
1686        override = context.copy()
1687        override['object'] = ob
1688
1689        image_width, image_height = int(self.image_width), int(self.image_height)
1690
1691        if self.image_name in context.blend_data.images:
1692            img = context.blend_data.images[self.image_name]
1693        else:
1694            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1695
1696        area = common.get_request_area(context, 'IMAGE_EDITOR')
1697        common.set_area_space_attr(area, 'image', img)
1698        for elem in me.uv_textures.active.data:
1699            elem.image = img
1700
1701        material_restore = common.material_restore(ob)
1702
1703        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
1704        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
1705            data_to.materials = ["精液"]
1706
1707        bpy.ops.object.material_slot_add(override)
1708        temp_mate = data_to.materials[0]
1709        ob.material_slots[0].material = temp_mate
1710        temp_mate.texture_slots[0].scale = (self.texture_scale, self.texture_scale, self.texture_scale)
1711
1712        context.scene.render.bake_type = 'TEXTURE'
1713        context.scene.render.use_bake_selected_to_active = False
1714        bpy.ops.object.bake_image()
1715
1716        common.remove_data([temp_mate, temp_mate.texture_slots[0].texture, temp_mate.texture_slots[0].texture.image])
1717
1718        material_restore.restore()
1719
1720        return {'FINISHED'}
bl_idname = 'object.quick_semen_bake_image'
bl_label = '白い液体・ベイク'
bl_description = 'アクティブオブジェクトに白い液体をベイクします'
bl_options = {'REGISTER', 'UNDO'}
image_name: <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': '画像名', 'attr': 'image_name'}>
items = [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)]
image_width: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '幅', 'default': '1024', 'attr': 'image_width'}>
image_height: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}> = <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('128', '128 px', '', 'LAYER_USED', 1), ('256', '256 px', '', 'LAYER_ACTIVE', 2), ('512', '512 px', '', 'HAND', 3), ('1024', '1024 px', '', 'FILE_TICK', 4), ('2048', '2048 px', '', 'ERROR', 5), ('4096', '4096 px', '', 'CANCEL', 6)], 'name': '高', 'default': '1024', 'attr': 'image_height'}>
texture_scale: <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'テクスチャサイズ', 'default': 1, 'min': 0, 'max': 100, 'soft_min': 0, 'soft_max': 100, 'step': 50, 'precision': 1, 'attr': 'texture_scale'}> = <_PropertyDeferred, <built-in function FloatProperty>, {'name': 'テクスチャサイズ', 'default': 1, 'min': 0, 'max': 100, 'soft_min': 0, 'soft_max': 100, 'step': 50, 'precision': 1, 'attr': 'texture_scale'}>
@classmethod
def poll(cls, context):
1655    @classmethod
1656    def poll(cls, context):
1657        if len(context.selected_objects) != 1:
1658            return False
1659        ob = context.active_object
1660        if ob:
1661            if ob.type == 'MESH':
1662                me = ob.data
1663                if len(me.uv_layers):
1664                    return True
1665        return False
def invoke(self, context, event):
1667    def invoke(self, context, event):
1668        ob = context.active_object
1669        self.image_name = ob.name + " Semen Bake"
1670        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
1672    def draw(self, context):
1673        self.layout.label(text="新規画像設定", icon='IMAGE_COL')
1674        self.layout.prop(self, 'image_name', icon='SORTALPHA')
1675        row = self.layout.row(align=True)
1676        row.prop(self, 'image_width', icon='ARROW_LEFTRIGHT')
1677        row.prop(self, 'image_height', icon='NLA_PUSHDOWN')
1678
1679        self.layout.prop(self, 'texture_scale', icon='TEXTURE')
def execute(self, context):
1681    def execute(self, context):
1682        ob = context.active_object
1683        me = ob.data
1684        ob.hide_render = False
1685
1686        override = context.copy()
1687        override['object'] = ob
1688
1689        image_width, image_height = int(self.image_width), int(self.image_height)
1690
1691        if self.image_name in context.blend_data.images:
1692            img = context.blend_data.images[self.image_name]
1693        else:
1694            img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True)
1695
1696        area = common.get_request_area(context, 'IMAGE_EDITOR')
1697        common.set_area_space_attr(area, 'image', img)
1698        for elem in me.uv_textures.active.data:
1699            elem.image = img
1700
1701        material_restore = common.material_restore(ob)
1702
1703        blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend")
1704        with context.blend_data.libraries.load(blend_path) as (data_from, data_to):
1705            data_to.materials = ["精液"]
1706
1707        bpy.ops.object.material_slot_add(override)
1708        temp_mate = data_to.materials[0]
1709        ob.material_slots[0].material = temp_mate
1710        temp_mate.texture_slots[0].scale = (self.texture_scale, self.texture_scale, self.texture_scale)
1711
1712        context.scene.render.bake_type = 'TEXTURE'
1713        context.scene.render.use_bake_selected_to_active = False
1714        bpy.ops.object.bake_image()
1715
1716        common.remove_data([temp_mate, temp_mate.texture_slots[0].texture, temp_mate.texture_slots[0].texture.image])
1717
1718        material_restore.restore()
1719
1720        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("OBJECT_OT_quick_semen_bake_image")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data